Get started

This document explains how to start to develop with the Awareness API on Android. The Awareness API is part of Google Play services.

To use the Awareness API, you need a Google Account. 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 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 {
    allprojects {
        repositories {
  2. Add the dependencies for the Awareness API to your module's app-level Gradle file, which is usually app/build.gradle:

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

  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() 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.
        .addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
            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: