manoj.y@epic

Native android ArcGIS(100.3.0) token authentication

Discussion created by manoj.y@epic on Nov 4, 2018

I'm using arcGIS version 100.3.0 I'm trying to load points on arcGIS map from arcGIS server. I'm successfully able to do that but I'm not sure how to pass token to the arcGIS server with the URL_POINTS. Following is the code without passing token which I found from the documentation which is working fine.

My code snippet is

credential = UserCredential.createFromToken(gisToken, referer);

ServiceFeatureTable featureTablePolygons = new ServiceFeatureTable(Utilities.checkNull(polygonUrl));
featureTablePolygons.setCredential(credential);

QueryParameters query = new QueryParameters();
query.setWhereClause(queryString);


//query feature from the table
final ListenableFuture<FeatureQueryResult> queryResultPolygons = featureTablePolygons.queryFeaturesAsync(query);
queryResultPolygons.addDoneListener(() -> {
try {
FeatureCollection featureCollection = new FeatureCollection();
FeatureQueryResult result = queryResultPolygons.get();
FeatureCollectionTable featureCollectionTable = new FeatureCollectionTable(result);
featureCollectionTable.setRenderer(new SimpleRenderer(new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, getResources().getColor(R.color.translucent_red), new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 1))));
featureCollection.getTables().add(featureCollectionTable);
FeatureCollectionLayer featureCollectionLayer = new FeatureCollectionLayer(featureCollection);
mMapView.getMap().getOperationalLayers().add(featureCollectionLayer);

if (result.iterator().hasNext()) {
Feature feature = result.iterator().next();
Envelope envelope = feature.getGeometry().getExtent();
mMapView.setViewpointGeometryAsync(envelope);
} else {
// Toast.makeText(mContext, "No polygons found for " + queryString, Toast.LENGTH_SHORT).show();
}
} catch (InterruptedException | ExecutionException e) {
Log.e(TAG, "Error in FeatureQueryResult: " + e.getMessage());
}
});



Passing username and password works fine using below code

MyAuthenticatioChallengeHandler handler = new MyAuthenticatioChallengeHandler();
AuthenticationManager.setAuthenticationChallengeHandler(handler);

class MyAuthenticatioChallengeHandler implements AuthenticationChallengeHandler {
private String USERNAME = "username";
private String USERPASSWORD = "password";

@Override
public AuthenticationChallengeResponse handleChallenge(AuthenticationChallenge authenticationChallenge) {
if (authenticationChallenge.getType() == AuthenticationChallenge.Type.USER_CREDENTIAL_CHALLENGE) {
return new AuthenticationChallengeResponse(
AuthenticationChallengeResponse.Action.CONTINUE_WITH_CREDENTIAL,
new UserCredential(USERNAME, USERPASSWORD));
} else {
Log.e(TAG, "USER CREDENTIAL challenge else");
return null;
}
}
}

Outcomes