**Deprecation notice: Awareness API is deprecated.**

> [!WARNING]
> **Warning:** The Awareness API is deprecated.
>
> - Google Play services will stop supporting the Awareness API in a future release, as early as January 2027.
> - There is no direct replacement.

To query for the current state of a fence, call
[`FenceClient.queryFences()`](https://developers.google.com/android/reference/com/google/android/gms/awareness/FenceClient.md.txt#public-taskfencequeryresponse-queryfences-fencequeryrequest-fencequeryrequest) and pass the fence key for the fence to query.

The following example calls `FenceClient.queryFences()` to get a `FenceStateMap`,
and then uses the `FenceStateMap` to return a
[`FenceState`](https://developers.google.com/android/reference/com/google/android/gms/awareness/fence/FenceState.md.txt)
value to show the current state, previous state, and the time when the fence was
last updated:

    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;
                }
            });
    }