Select to view content in your preferred language

Using Secure Services in SDK

1967
2
01-25-2012 07:55 AM
JustinGreco
Frequent Contributor
I am developing an app that uses a secured map service.  I have read about using the UserCredentials class to specify a user name and password.  However, when I try to add the secure service, the service is failing to initialize.  I have read that the ArcGIS for Android app does not support secure services yet, does the SDK not either?
0 Kudos
2 Replies
DanO_Neill
Deactivated User
Yes, this is supported in the SDK.  To use a service that requires tokens, you must first obtain a token, and then embed the token in your application.  Once you have a valid token you can add it to your application code using the ArcGISFeaturelayer constructor. In order to create a token based secure layer you must construct a UserCredential with a token and pass it into the ArcGISFeaturelayer constructor.

UserCredentials credentials =new UserCredentials();
credentials.setUserToken("PLACE_YOUR_TOKEN_HERE", "URL_REFERRER");
tokenLayer = new ArcGISFeatureLayer("SECURE FEATURE SERVICE URL", MODE.SNAPSHOT, credentials);


Replacing BOLD text with appropriate parameters.

The same philosophy applies to WebMap. Do not put a token based URL as your web map layer�??s URL. The correct way to include a secure layer in webmap.

    1. Include the layer�??s URL without a token
    2. If layer initialization fails and it is a security exception, ask for user�??s credential
    3.  Re-initialize the layer with user credential.
0 Kudos
JustinGreco
Frequent Contributor
Thanks for the response.  I had the code correct, but the issue was with how I had the security set up in ArcGIS Server.  I got that resolved and the feature layer is drawing.
0 Kudos