Hi,
I've been downloading offline map areas using a credential as seen below:
Whenever I set ArcGISRuntimeEnvironment.setApiKey("apiKey"), the preplannedMapAreas comes out as empty, but when I have not set the apiKey in the runtime environment, it returns the list. Same thing happens if I have not set the credential above and set the apiKey.
I would like to know if there is a way to set the apiKey locally in a function, instead of globally, so that I can still load the arcgis map with the apiKey, without making it so I cannot download the preplanned map area.
Alternatively, is there a way of loading an arcgis map without the api key, but using the credentials instead?
Thanks for reading!
Hello. Thanks for the question.
At the moment there is a known limitation in ArcGIS Online that prevents the Preplanned Offline Map workflow working with API Keys. Credentials will work, as you've noticed. However, what you're encountering is that the way the SDK is architected, if you set a global API Key on the ArcGISRuntimeEnvironment, then that will be used without even considering any credential you might set.
One thing you could try to do is to clear the global API Key before running your code above and then setting it again once the callbacks have completed. That will clear the way for the OfflineMapTask to use the credential you provide.
I do want to clarify one thing though. You say "Same thing happens if I have not set the credential above and set the apiKey." Can you confirm that you mean that if you do not set the credential, but do set the apiKey, then the preplannedMapAreas come out as empty? (this is what I would expect)
I would like to know if there is a way to set the apiKey locally in a function, instead of globally, so that I can still load the arcgis map with the apiKey
Unfortunately not in this case. Typically, anything that implements ApiKeyResource can be provided an explicit API Key to use in preference to any other authentication method (including a global API Key). However, in the case of a Map opening a web map, there are some nuanced reasons that meant we could not expose that functionality in this case, and so the only way to use an API Key to access a web map is to use the global API Key. It's something we plan to review and see if we can improve, but currently that's a known limitation with API Keys and web maps.
Alternatively, is there a way of loading an arcgis map without the api key, but using the credentials instead?
Absolutely, however if there's a global API Key set, as I mentioned above, that will override any credential in this case.
Does this help?
Thanks for the response!
Yes this helps a lot thank you, and yes I do mean I set the credential and not the API key.