0

Below is the code I'm using for setting user credentials on ServiceFeatureTable.

ServiceFeatureTable featureTablePolygons = new ServiceFeatureTable(polygonUrl);
featureTablePolygons.setCredential(UserCredential.createFromToken(gisToken, referer));


    //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 {
            }
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Error in FeatureQueryResult: " + e.getMessage());
        }
    });

But this is not working. If I'm using AuthenticationManager then it's working fine but I don't want to use username and password in my code.

Manoj
  • 1
  • 1

1 Answers1

0

If you're manually getting the token, you can create a UserCredential object using createFromToken() and set it on the ServiceFeatureTable with setCredential().

However, many workflows for getting a token are handled by the Runtime (e.g. username + password, or OAuth via a Portal). Take a look at the AuthenticationManager documentation to get started.

Lastly, I think you'll get more eyes on your questions over at the ArcGIS Runtime SDK for Android forums.

Nixta
  • 464
  • 2
  • 10
  • Thanks for your reply. I've asked this question on the ArcGIS forum but nobody answered. – Manoj Nov 12 '18 at 07:03
  • What's the error you're getting? And what's the referrer you're using? If you set the referrer to ArcGISRuntimeEnvironment.getUserAgent(), does that change anything? I'm not expecting it does, but I've seen that pattern used elsewhere. – Nixta Nov 12 '18 at 17:01
  • if I use featureTablePolygons.setCredential(new UserCredential(username, password)); then it's working fine but as soon as I change it to featureTablePolygons.setCredential(UserCredential.createFromToken(gisToken, referer)); It throws ArcGISRuntimeException: Cannot call this method in this context at queryResultPolygons.get(); – Manoj Nov 16 '18 at 05:39