android – 围栏状态的Awareness API查询

前端之家收集整理的这篇文章主要介绍了android – 围栏状态的Awareness API查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过Awareness API获得fence状态.这是关于这个的 documentation.但……使用时:
Awareness.FenceApi.queryFences

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

Awareness.getFenceClient

任何人都可以举个例子来说明如何使用getFenceClient获取fence状态?

解决方法

得到它了:
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);
                }
            });
原文链接:https://www.f2er.com/android/318402.html

猜你在找的Android相关文章