I am trying to get step count from google fit inside an Android app. App successfully gets called to onConnected()
after selecting the google account. I have configured the Google API Console with correct SHA1 finger print and package name too. So there cannot be any wrong with Console.
However it never gets hit to onDataPoint()
[this used to work before].
I am pasting the code after onConnected
here.
DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build();
ResultCallback<DataSourcesResult> dataSourcesResultCallback = new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
if (DataType.TYPE_STEP_COUNT_CUMULATIVE.equals(dataSource.getDataType())) {
registerFitnessDataListener(dataSource, DataType.TYPE_STEP_COUNT_CUMULATIVE);
}
}
}
};
Fitness.SensorsApi.findDataSources(mApiClient, dataSourceRequest)
.setResultCallback(dataSourcesResultCallback);
and then
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
Log.e("GoogleFit", "registerFitnessDataListener");
SensorRequest request = new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(3, TimeUnit.SECONDS)
.build();
Fitness.SensorsApi.add(mApiClient, request, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.e("GoogleFit", "SensorApi successfully added");
}
}
});
}
Can someone help me with the reason why it is not getting hit inside onDataPoint()
method??
I solved it by using DataSource.TYPE_DERIVED when building the DataSourcesRequest. I think this happens as a result of my testing device which is Nexus 7 is having a software sensor rather than hardware sensor. As a result off that I cannto get results for TYPE_STEP_COUNT_DELTA.