【问题标题】:Awareness API Query for Fence State围栏状态的 Awareness API 查询
【发布时间】:2018-06-03 12:58:55
【问题描述】:

我正在尝试使用 Awareness API 获取围栏状态。这是关于此的documentation。但是...使用时:

Awareness.FenceApi.queryFences

我可以看到它的deprecated,而需要使用:

Awareness.getFenceClient

谁能给我一个示例如何使用 getFenceClient 获取围栏状态?

【问题讨论】:

    标签: android google-awareness


    【解决方案1】:

    知道了:

    Awareness.getFenceClient(context).queryFences(FenceQueryRequest.forFences(Arrays.asList(key)))
                .addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {
    
                    @Override
                    public void onSuccess(FenceQueryResponse fenceQueryResponse) {
    
                        FenceStateMap map = fenceQueryResponse.getFenceStateMap();
    
                        for (String fenceKey : map.getFenceKeys()) {
                            FenceState fenceState = map.getFenceState(fenceKey);
                            Log.i(TAG, "Fence " + fenceKey + ": "
                                    + fenceState.getCurrentState()
                                    + ", was="
                                    + fenceState.getPreviousState());
                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
    
                        Log.d(TAG, "Failed: " + e);
                    }
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      相关资源
      最近更新 更多