【发布时间】:2016-08-31 07:07:51
【问题描述】:
我正在尝试从 google fit API 获取步数、距离和卡路里。
我使用GoogleApiClient 访问来自 Google Fit 的数据。
我要求每个 Google Fit 许可也允许访问来自 Google Fit 的所有数据:
每次都会弹出此权限。我需要允许 4 到 5 次才能从 Google Fit 获取步骤。
第一次获得 Google Fit 许可我需要做什么。 所以请帮我解决这个问题。
mGoogleApiClient1 = new GoogleApiClient.Builder(this)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addScope(new Scope(Scopes.FITNESS_BODY_READ_WRITE))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE))
.addConnectionCallbacks(this)
.enableAutoManage(this, Constants.googleApi, this)
.build();
2。我使用下面的 API 来获取步数距离和卡路里 请说明为什么我没有从 Google Fit 获得一致的数据。 它总是从 Google Fit 获取步数数据,比原始步数多一点。
// get Steps data from bellow api
private void getStepDataForToday() {
DailyTotalResult result = Fitness.HistoryApi.readDailyTotal( mGoogleApiClient1, DataType.TYPE_STEP_COUNT_DELTA ).await(1, TimeUnit.MINUTES);
showDataSet(result.getTotal());
}
private void getDistanceDataForToday() {
DailyTotalResult result = Fitness.HistoryApi.readDailyTotal( mGoogleApiClient1, DataType.TYPE_DISTANCE_DELTA ).await(1, TimeUnit.MINUTES);
showDataSet(result.getTotal());
}
private void getCaloriesDataForToday() {
DailyTotalResult result = Fitness.HistoryApi.readDailyTotal( mGoogleApiClient1, DataType.TYPE_CALORIES_EXPENDED ).await(1, TimeUnit.MINUTES);
showDataSet(result.getTotal());
}
谢谢 等待帮助
【问题讨论】:
-
请先编辑你的问题,检查这个:stackoverflow.com/help/formatting
标签: android google-fit