简体   繁体   English

围栏状态的意识API查询

[英]Awareness API Query for Fence State

I am trying to get fence state with the Awareness API. 我正在尝试使用Awareness API获取隔离状态。 Here is the documentation about this. 这是关于此的文档 But... When using: 但是...使用时:

Awareness.FenceApi.queryFences

I can see its deprecated , and instead need to use: 我可以看到它已弃用 ,而需要使用:

Awareness.getFenceClient

Can anyone please give me an example how to get fence status with getFenceClient? 谁能给我一个例子,如何通过getFenceClient获取围栏状态?

Got it: 得到它了:

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);
                }
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM