We're making some changes to the Google Fit APIs. Learn about how these changes might affect your app. Read our new policy.

Access Raw Sensor Data

The Sensors API lets you read raw sensor data in your app in real time. Use this API to:

  • List data sources available on the device and on companion devices.
  • Register listeners to receive raw sensor data.
  • Unregister listeners to stop receiving raw sensor data.

The Sensors API does not automatically store sensor readings in the fitness store and sensor registrations created with the Sensors API are not persisted when the system restarts. You typically use the Recording API to record data in the background with persistent subscriptions and you use the Sensors API to display or process sensor readings in real time. In many cases, you use both of these APIs in your app.

List available data sources

To obtain a list of all available data sources on the device and on companion devices, use the SensorsClient.findDataSources method:

// Note: SensorsClient#findDataSources() requires the ACCESS_FINE_LOCATION permission.
Fitness.getSensorsClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
        new DataSourcesRequest.Builder()
    .addOnSuccessListener(dataSources -> {
        for (DataSource dataSource : dataSources) {
            Log.i(TAG, "Data source found: " + dataSource.toString());
            Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());

            // Let's register a listener to receive Activity data!
            if (dataSource.getDataType().equals(DataType.TYPE_LOCATION_SAMPLE)) {
              Log.i(TAG, "Data source for LOCATION_SAMPLE found!  Registering.");
              registerFitnessDataListener(dataSource, DataType.TYPE_LOCATION_SAMPLE);
    .addOnFailureListener(e -> {
        Log.e(TAG, "failed", e);

To get information about the device for a data source, use the DataSource.getDevice method. The device information is useful to distinguish from similar sensors on different devices, show the device information from a sensor to the user, or process data differently depending on the device. For example, you may be interested in reading data specifically from the sensor on a wearable device but not from the same type of sensor on the phone.

To get a Device instance for the device that is running your activity, use the Device.getLocalDevice static method. This is useful when you want to check if a data source is on the same device that your app is running on.

Add a listener

To add a listener to receive raw data of a particular fitness data type or from a specific data source, use the SensorsClient.add method:

OnDataPointListener listener = dataPoint -> {
    for (Field field : dataPoint.getDataType().getFields()) {
        Value val = dataPoint.getValue(field);
        Log.i(TAG, "Detected DataPoint field: " + field.getName());
        Log.i(TAG, "Detected DataPoint value: " + val);

Fitness.getSensorsClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
        new SensorRequest.Builder()
            .setDataSource(dataSource) // Optional but recommended for custom data sets.
            .setDataType(dataType) // Can't be omitted.
            .setSamplingRate(10, TimeUnit.SECONDS)
    .addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
          Log.i(TAG, "Listener registered!");
        } else {
          Log.e(TAG, "Listener not registered.", task.getException());

Remove a listener

To remove a listener from raw data updates, use the SensorsClient.remove method:

Fitness.getSensorsClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
    .addOnCompleteListener(task -> {
        if (task.isSuccessful() && task.getResult()) {
            Log.i(TAG, "Listener was removed!");
        } else {
            Log.i(TAG, "Listener was not removed.");