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

This document explains how to start to develop with the Awareness API on
Android. The Awareness API is part of [Google Play services](https://developers.google.com/android/guides/overview.md.txt).

To use the Awareness API, you need a [Google Account](https://www.google.com/accounts/NewAccount).
If you already have an account, then you're all set. You might also want a
separate Google Account for testing purposes.

## Before you begin

### Obtain an API key

If you haven't already enabled the Awareness API and obtained a Google API key,
follow the steps in [Signup and API keys](https://developers.google.com/awareness/android-api/get-a-key.md.txt)
to do so.

### Configure your app

1. In your project-level `build.gradle` file, include Google's Maven repository
   in both your `buildscript` and `allprojects` sections:

       buildscript {
           repositories {
               google()
           }
       }

       allprojects {
           repositories {
               google()
           }
       }

2. Add the dependencies for the Awareness API to your module's app-level
   Gradle file, which is usually `app/build.gradle`:

       dependencies {
         implementation 'com.google.android.gms:play-services-awareness:20.0.0'
       }

3. Add your Awareness API Key to your app's `AndroidManifest.xml` file. To do
   so, add a `<meta-data>` tag with
   `android:name="com.google.android.awareness.API_KEY"`. For `android:value`,
   insert your own Awareness API Key, surrounded by quotation marks.

   ```xml
   <manifest>
       <application>
           <meta-data
               android:name="com.google.android.awareness.API_KEY"
               android:value="API_KEY"/>
       </application>
   </manifest>
   ```
4. Add the necessary permissions to your app's `AndroidManifest.xml` file. The
   required permissions vary, depending on the API methods and fence types that
   your app uses.

## Example call

The following example call to
[`getDetectedActivity()`](https://developers.google.com/android/reference/com/google/android/gms/awareness/SnapshotClient.md.txt#getDetectedActivity())
demonstrates how to use the connectionless Google Play services model with the
Awareness API:

        // Each type of contextual information in the snapshot API has a corresponding "get" method.
        // For instance, this is how to get the user's current Activity.
        Awareness.getSnapshotClient(this).getDetectedActivity()
            .addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
                @Override
                public void onSuccess(DetectedActivityResponse dar) {
                    ActivityRecognitionResult arr = dar.getActivityRecognitionResult();
                    // getMostProbableActivity() is good enough for basic Activity detection.
                    // To work within a threshold of confidence,
                    // use ActivityRecognitionResult.getProbableActivities() to get a list of
                    // potential current activities, and check the confidence of each one.
                    DetectedActivity probableActivity = arr.getMostProbableActivity();

                    int confidence = probableActivity.getConfidence();
                    String activityStr = probableActivity.toString();
                    mLogFragment.getLogView().println("Activity: " + activityStr
                        + ", Confidence: " + confidence + "/100");
                }
            })

## Next steps

Learn more about the different APIs within the Awareness API:

- [Snapshot API guide](https://developers.google.com/awareness/android-api/snapshot-api-overview.md.txt) and [Snapshot API reference](https://developers.google.com/android/reference/com/google/android/gms/awareness/snapshot/package-summary.md.txt).
- [Fence API guide](https://developers.google.com/awareness/android-api/fence-api-overview.md.txt) and [Fence API
  reference](https://developers.google.com/android/reference/com/google/android/gms/awareness/fence/package-summary).