我试图通过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); } });