Snapshot API Overview

You can use the Snapshot API to get information about the user's current environment. Using the Snapshot API, you can access a variety of context signals:

  • Detected user activity, such as walking or driving.
  • Nearby beacons that you have registered.
  • Headphone state (plugged in or not).
  • Location, including latitude and longitude.
  • Place where the user is currently located.
  • Weather conditions in the user's current location.

The system caches these values so that they can be returned quickly; if there is no data, sensing and inference are performed to return fresh state values. The Awareness API returns the existing data type for context types that have a public API. For example, the call to SnapshotApi.getPlaces() returns a list of PlaceLikelihood instances, from which you can get data about the places near the user's current location.

Each context signal has a corresponding Snapshot API method. For example, to get the current detected activity, you would call SnapshotAPI.getDetectedActivity(), use a ResultCallback to get a DetectedActivityResult, then call DetectedActivityResult.getActivityRecognitionResult() to return an ActivityRecognitionResult from which you can get the actual request data. The following example shows getting the latest detected activity:

        .setResultCallback(new ResultCallback<DetectedActivityResult>() {
            public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
                if (!detectedActivityResult.getStatus().isSuccess()) {
                    Log.e(TAG, "Could not get the current activity.");
                ActivityRecognitionResult ar = detectedActivityResult.getActivityRecognitionResult();
                DetectedActivity probableActivity = ar.getMostProbableActivity();
                Log.i(TAG, probableActivity.toString());

Send feedback about...

Google Awareness API