【问题标题】:ArcGIS version 100.3.0 android tokenArcGIS 100.3.0 版安卓令牌
【发布时间】:2018-09-10 06:41:40
【问题描述】:

下面是我用于在 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());
        }
    });

但这不起作用。如果我使用的是 AuthenticationManager,那么它工作正常,但我不想在我的代码中使用用户名和密码。

【问题讨论】:

    标签: arcgis-runtime arcgis-android-api


    【解决方案1】:

    如果您手动获取令牌,您可以使用 createFromToken() 创建一个 UserCredential 对象,并使用 setCredential() 在 ServiceFeatureTable 上设置它。

    但是,许多获取令牌的工作流由运行时处理(例如,用户名 + 密码,或通过门户的 OAuth)。请查看AuthenticationManager documentation 以开始使用。

    最后,我想你会在ArcGIS Runtime SDK for Android forums 得到更多的关注。

    【讨论】:

    • 感谢您的回复。我在 ArcGIS 论坛上问过这个问题,但没有人回答。
    • 您遇到了什么错误?你使用的推荐人是什么?如果您将引用者设置为 ArcGISRuntimeEnvironment.getUserAgent(),这会改变什么吗?我没想到会这样,但我在其他地方看到过这种模式。
    • 如果我使用 featureTablePolygons.setCredential(new UserCredential(username, password));然后它工作正常,但是一旦我将其更改为 featureTablePolygons.setCredential(UserCredential.createFromToken(gisToken, referer));它抛出 ArcGISRuntimeException: Cannot call this method in this context at queryResultPolygons.get();
    猜你喜欢
    • 2021-04-16
    • 2018-09-05
    • 2013-11-21
    • 2016-03-29
    • 1970-01-01
    • 2011-09-25
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多