我正在尝试使用 Awareness API 获取围栏状态。这是有关此的文档。但是...使用时:
Awareness.FenceApi.queryFences
我可以看到它deprecated,而是需要使用:
Awareness.getFenceClient
谁能给我一个示例如何使用 getFenceClient 获取围栏状态?
我正在尝试使用 Awareness API 获取围栏状态。这是有关此的文档。但是...使用时:
Awareness.FenceApi.queryFences
我可以看到它deprecated,而是需要使用:
Awareness.getFenceClient
谁能给我一个示例如何使用 getFenceClient 获取围栏状态?
知道了:
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);
}
});