gpt4 book ai didi

android - 第一次未授予 Google Fit 权限

转载 作者:行者123 更新时间:2023-11-30 01:02:34 28 4
gpt4 key购买 nike

我正在尝试从 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());
}

谢谢等待帮助

最佳答案

对于 Fit 权限,请确保或仔细检查您是否正确遵循 Authorization in Android 中的说明.

您获得的步数、距离和卡路里数据与 Google Fit 的原始步数差不多?

它在 FAQ 中说明Google FIT:

Because of how Google Fit updates are released, it may be possible that the Google Fit app has a more recent version of our data analysis code than Google Play Services, which is released less often.

Our backends, however, always have the most recent version of the data, and everything gets processed there eventually and should match up after a couple of cloud syncs. Let us know if that’s not the case.

We’re trying to make this situation better by making it possible for apps to request that we process a cloud sync instantly so that everything is in sync, and also by making it so that syncs happen automatically when significant data is entered or changes.

This could also be caused by not reading the proper data sources. To match the value of Google Fit, you should be reading data like this:

DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build();
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();

有关更多信息,请查看此相关SO question .

关于android - 第一次未授予 Google Fit 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39242912/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com