public abstract class

FitnessSensorService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ com.google.android.gms.fitness.service.FitnessSensorService

Class Overview

A service which allows an installed application to expose sensors to Google Fit, so that they can be used by other applications through the standard SensorsApi. The service supports finding, registering, and unregistering to application-exposed sensors.

Applications should implement the FitnessSensorService when they have access to live sensor data from external devices that are not otherwise compatible with the platform. An example would be a hardware pedometer that connects to the phone via standard Bluetooth. A companion application could expose the pedometer's readings to the platform.

The FitnessSensorService can also be used to expose software sensors. For instance, an application may compute step count data in software based on other hardware sensors (such as the accelerometer). The computed data can be made available using this service.

To add an application-exposed sensor to the platform, a subclass of FitnessSensorService must be declared in the manifest as such:

      <service
         android:name="com.example.android.fitness.MySensorService"
         android:exported="true">
         <intent-filter>
             <action android:name="com.google.android.gms.fitness.service.FitnessSensorService" />
             <data android:mimeType="vnd.google.fitness.data_type/com.google.heart_rate.bpm" />
         </intent-filter>
      </service>
 

The declared service must include one or more mimeType filters, indicating which data types it supports. If no data type is listed, the service will be ignored.

The service will be used to find, register, and unregister to the application-exposed sensors. When an active registration exists, Google Fit will bind to the service, and will remain bound until all registrations are removed. In this way, the platform is able to control the lifetime of the sensor service.

The Fitness Platform has built-in support for local hardware sensors, BLE devices with standard GATT profiles, and Android Wear devices. Accessing these sensors does not require a custom FitnessSensorService.

Summary

Constants
String SERVICE_INTERFACE Intent action that must be declared in the manifest for the subclass.
[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2
Public Constructors
FitnessSensorService()
Public Methods
final IBinder onBind(Intent intent)
void onCreate()
abstract List<DataSource> onFindDataSources(List<DataType> dataTypes)
Find application data sources which match the given data types.
abstract boolean onRegister(FitnessSensorServiceRequest request)
Registers for events from a particular data source at a given rate.
abstract boolean onUnregister(DataSource dataSource)
Unregisters for events from a particular data source.
[Expand]
Inherited Methods
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2

Constants

public static final String SERVICE_INTERFACE

Intent action that must be declared in the manifest for the subclass. Used to start the service to find and register to application-exposed sensors.

Constant Value: "com.google.android.gms.fitness.service.FitnessSensorService"

Public Constructors

public FitnessSensorService ()

Public Methods

public final IBinder onBind (Intent intent)

public void onCreate ()

public abstract List<DataSource> onFindDataSources (List<DataType> dataTypes)

Find application data sources which match the given data types.

Parameters
dataTypes the data types that the client is interested in
Returns
  • the list of data sources which this application can expose that match the given data types, empty if there is no match

public abstract boolean onRegister (FitnessSensorServiceRequest request)

Registers for events from a particular data source at a given rate. Events should be delivered to the fitness platform using the dispatcher specified in the request, accessible via getDispatcher().

In case an active registration to the given data source already exists, the request should be treated as an update. In case the given data source is no longer exposed by this application, the request can be ignored and false returned.

Parameters
request request specifying the data source to register to, the desired sampling rate, and the desired batching interval
Returns
  • true if we were able to register to a matching data source

public abstract boolean onUnregister (DataSource dataSource)

Unregisters for events from a particular data source.

Parameters
dataSource the data source we wish to stop receiving events from
Returns
  • true if we were able to unregister from a matching data source