Bir çitin mevcut durumunu sorgulamak için FenceClient.queryFences()
numaralı telefonu arayın ve sorgulanacak çitin çit anahtarını iletin.
Aşağıdaki örnekte, FenceClient.queryFences()
çağrısı yapılarak FenceStateMap
elde edilir. Ardından, mevcut durumu, önceki durumu ve sınırlamanın son güncellendiği zamanı göstermek için FenceStateMap
kullanılarak FenceState
değeri döndürülür:
protected void queryFence(final String fenceKey) {
Awareness.getFenceClient(this)
.queryFences(FenceQueryRequest.forFences(Arrays.asList(fenceKey)))
.addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {
@Override
public void onSuccess(FenceQueryResponse response) {
FenceStateMap map = response.getFenceStateMap();
for (String fenceKey : map.getFenceKeys()) {
FenceState fenceState = map.getFenceState(fenceKey);
Log.i(TAG, "Fence " + fenceKey + ": "
+ fenceState.getCurrentState()
+ ", was="
+ fenceState.getPreviousState()
+ ", lastUpdateTime="
+ DATE_FORMAT.format(
new Date(fenceState.getLastFenceUpdateTimeMillis())));
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Could not query fence: " + fenceKey);
return;
}
});
}