Android APIs
public abstract class

ApplicationSensorService

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

Class Overview

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

Applications should implement the ApplicationSensorService when they have access to real-time 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 ApplicationSensorService 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 sensor to the platform, a subclass of ApplicationSensorService must be declared in the manifest as such:

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

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

The service will be used to find, register, and unregister to the application sensors. When an active registration exists, the Fitness Platform 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 an ApplicationSensorService.

Summary

Constants
String START_SERVICE_ACTION 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
ApplicationSensorService()
Public Methods
IBinder onBind(Intent intent)
void onCreate()
Protected Methods
abstract List<DataSource> findDataSources(List<DataType> dataTypes)
Find application data sources which math the given data types.
abstract boolean register(ApplicationSensorRequest request)
Registers for events from a particular data source at a given rate.
abstract boolean unregister(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 START_SERVICE_ACTION

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

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

Public Constructors

public ApplicationSensorService ()

Public Methods

public IBinder onBind (Intent intent)

public void onCreate ()

Protected Methods

protected abstract List<DataSource> findDataSources (List<DataType> dataTypes)

Find application data sources which math 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 math the given data types, empty if there is no match

protected abstract boolean register (ApplicationSensorRequest 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

protected abstract boolean unregister (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