我正在尝试使用Awareness API获取fence状态。这是关于此的documentation。但是......使用时:
Awareness.FenceApi.queryFences
我可以看到它的deprecated,而是需要使用:
Awareness.getFenceClient
有谁能请举例说明如何使用getFenceClient获取围栏状态?
答案 0 :(得分:2)
知道了:
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);
}
});