implements HasApiKey < Api.ApiOptions.HasGoogleSignInAccountOptions >
Client which enables low-power, always-on background collection of local sensor data.
Sensor subscriptions are active when the requesting app is not running, and persisted through
system restarts. Collected data can be queried using readData(LocalDataReadRequest)
.
Constant Summary
int | LOCAL_RECORDING_CLIENT_MIN_VERSION_CODE | The minimum version of Google Play services that LocalRecordingClient
requires. |
int | LOCAL_RECORDING_CLIENT_STEPS_MIN_VERSION_CODE | The minimum version of Google Play services that LocalRecordingClient
requires if only using LocalDataType.TYPE_STEP_COUNT_DELTA
. |
Public Method Summary
Task < LocalDataReadResponse > | |
Task < Void > | |
Task < Void > | unsubscribe
( LocalDataType
dataType)
Unsubscribes from background data collection for the current application for a
particular data type.
|
Inherited Method Summary
Constants
public static final int LOCAL_RECORDING_CLIENT_MIN_VERSION_CODE
The minimum version of Google Play services that LocalRecordingClient
requires. This version code can be used with use GoogleApiAvailability.isGooglePlayServicesAvailable(Context, int)
to check
whether the current version is sufficient.
This minimum version has support for LocalDataType.TYPE_STEP_COUNT_DELTA
, LocalDataType.TYPE_DISTANCE_DELTA
or LocalDataType.TYPE_CALORIES_EXPENDED
.
public static final int LOCAL_RECORDING_CLIENT_STEPS_MIN_VERSION_CODE
The minimum version of Google Play services that LocalRecordingClient
requires if only using LocalDataType.TYPE_STEP_COUNT_DELTA
. This version code can be used with use GoogleApiAvailability.isGooglePlayServicesAvailable(Context, int)
to check
whether the current version is sufficient.
This minimum version only has support for LocalDataType.TYPE_STEP_COUNT_DELTA
, use LOCAL_RECORDING_CLIENT_MIN_VERSION_CODE
if using LocalDataType.TYPE_DISTANCE_DELTA
or LocalDataType.TYPE_CALORIES_EXPENDED
.
Public Methods
public Task < LocalDataReadResponse > readData ( LocalDataReadRequest request)
Reads data from the user's local history. Values can be read in detailed or in aggregate formats. Aggregate data is presented in buckets, while detailed data is returned as a single data set.
Parameters
Returns
- A
Task
containing the requested data
Throws
SecurityException | If a required permission is missing for the requested LocalDataType
|
---|---|
ApiException | with status ConnectionResult.API_UNAVAILABLE
if the calling package is not allowed
to use the Recording API on mobile |
ApiException | with status FitnessStatusCodes.DATA_TYPE_NOT_ALLOWED_FOR_API
if the requested LocalDataType
is not currently supported |
ApiException | with status FitnessStatusCodes.API_EXCEPTION
if a valid subscription for a requested
data type is not found |
ApiException | with status ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
if the installed
version of Google Play services is out of date, in which case you should request
that the user updates Google Play services using GoogleApiAvailability
.
You can use GoogleApiAvailability.isGooglePlayServicesAvailable(Context, int)
with LOCAL_RECORDING_CLIENT_MIN_VERSION_CODE
. |
public Task < Void > subscribe ( LocalDataType dataType)
Subscribes to background collection of LocalDataType
on behalf of the current application.
After the subscription is successfully added, new data points in the requested data
stream are persisted for 10 days and can be queried via readData(LocalDataReadRequest)
.
If the requested subscription already exists, the request is a no-op.
Subscribing to a LocalDataType
which derives from data collected using activity recognition requires the ACTIVITY_RECOGNITION
runtime
permission if your app is targeting API level 29. If the permission is lost during
recording, the registration will be removed.
Parameters
Throws
SecurityException | If a required permission is missing for the requested LocalDataType
|
---|---|
ApiException | with status ConnectionResult.API_UNAVAILABLE
if the calling package is not allowed
to use the Recording API on mobile |
ApiException | with status FitnessStatusCodes.DATA_TYPE_NOT_ALLOWED_FOR_API
if the requested LocalDataType
is not currently supported |
ApiException | with status ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
if the installed
version of Google Play services is out of date, in which case you should request
that the user updates Google Play services using GoogleApiAvailability
.
You can use GoogleApiAvailability.isGooglePlayServicesAvailable(Context, int)
with LOCAL_RECORDING_CLIENT_MIN_VERSION_CODE
. |
public Task < Void > unsubscribe ( LocalDataType dataType)
Unsubscribes from background data collection for the current application for a particular data type. Should be called when the application no longer wishes to record data.
Unsubscribing from a LocalDataType
for which a subscription does not already exist is no-op.
Parameters
Throws
ApiException | with status ConnectionResult.API_UNAVAILABLE
if the calling package is not allowed
to use the Recording API on mobile |
---|---|
ApiException | with status ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
if the installed
version of Google Play services is out of date, in which case you should request
that the user updates Google Play services using GoogleApiAvailability
.
You can use GoogleApiAvailability.isGooglePlayServicesAvailable(Context, int)
with LOCAL_RECORDING_CLIENT_MIN_VERSION_CODE
. |