问题
I'm developing an app for Android (only for smartphone, not for wear) and I want to get the heart rate using googleApiClient
(Google Fit) from smartwatch (Huawei Watch f.e.). I tried using Sensor API but wear is not listed as DataSource
in Google Fit API.
REQUEST_INTERVAL = 5;
Fitness.SensorsApi.findDataSources(client, new DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_LOCATION_SAMPLE,
DataType.TYPE_STEP_COUNT_CUMULATIVE,
DataType.TYPE_DISTANCE_DELTA,
DataType.TYPE_HEART_RATE_BPM)
.setDataSourceTypes(DataSource.TYPE_RAW, DataSource.TYPE_DERIVED)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
// There isn't heart rate source here
final DataType dataType = dataSource.getDataType();
Fitness.SensorsApi.add(client,
new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(REQUEST_INTERVAL, TimeUnit.SECONDS)
.build(),
listener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
...
}
});
}
}
}
});
Othrer data(like steps, location and distance) are came. My client:
googleApiClient = new GoogleApiClient.Builder(activity)
.addApi(Plus.API)
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.SENSORS_API)
.addApi(LocationServices.API)
.addApi(Fitness.BLE_API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(new Scope(Scopes.PROFILE))
.addScope(new Scope(Scopes.PLUS_LOGIN))
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
I spent some hours reading docs and answers but can't find a solution. Maybe I do something wrong. Data from smartphone came, but from wear it doesn't. Google fit is installed on wear.
Thanks for your answer!
来源:https://stackoverflow.com/questions/40177237/get-heart-rate-from-android-wear-using-google-fit