**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.

Once a fence is registered, your app must add a callback to respond
when the fence is triggered. You can do this with the use of a subclass of
`BroadcastReceiver` to handle `Intent` methods from fences.

Before you add callbacks to a fence, you must first
[register](https://developers.google.com/awareness/android-api/fence-register.md.txt) the fence.

## Create a subclass of BroadcastReceiver

The following example shows the `FenceReceiver` class, which extends
`BroadcastReceiver`. The class implements the
`BroadcastReceiver.onReceive()` callback method to handle all `Intent` methods
that originate from fences created by your app. When an `Intent` is received, the
[`FenceState.extract()`](https://developers.google.com/android/reference/com/google/android/gms/awareness/fence/FenceState.md.txt#extract(android.content.Intent))
method is used to get the fence state and pass it to the callback.

    public class FenceReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

            FenceState fenceState = FenceState.extract(intent);

            if (TextUtils.equals(fenceState.getFenceKey(), FENCE_KEY)) {
                String fenceStateStr;
                switch (fenceState.getCurrentState()) {
                    case FenceState.TRUE:
                        fenceStateStr = "true";
                        break;
                    case FenceState.FALSE:
                        fenceStateStr = "false";
                        break;
                    case FenceState.UNKNOWN:
                        fenceStateStr = "unknown";
                        break;
                    default:
                        fenceStateStr = "unknown value";
                }
                mLogFragment.getLogView().println("Fence state: " + fenceStateStr);
            }
        }
    }