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 SensorsClient
.
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.
Constant Summary
String | SERVICE_INTERFACE | Intent action that must be declared in the manifest for the subclass. |
Inherited Constant Summary
Public Constructor Summary
Public Method Summary
IBinder | |
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 |
Inherited Method Summary
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.
Public Constructors
public FitnessSensorService ()
Public Methods
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
FitnessSensorServiceRequest.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
- Whether 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
- Whether we were able to unregister from a matching data source.