开发者社区> 问答> 正文

com.google.step_count.cumulative需要android.permissi

我正在尝试从android中的google-fit API检索BPM。但要获得com.google.step_count.cumulative错误,还需要清单文件中的android.permission.ACTIVITY_RECOGNITION包含权限:

private void readDataFitnessHistory() {
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();

    cal.add(Calendar.WEEK_OF_YEAR, -1);
    long startTime = cal.getTimeInMillis();

    java.text.DateFormat dateFormat = getDateInstance();
    Log.d("Range Start", "Range Start: " + dateFormat.format(startTime));
    Log.d("Range End", "Range End: " + dateFormat.format(endTime));

    DataReadRequest readRequest = new DataReadRequest.Builder()
            .aggregate(DataType.TYPE_HEART_RATE_BPM, DataType.AGGREGATE_HEART_RATE_SUMMARY)
            .bucketByTime(1, TimeUnit.DAYS)
            .enableServerQueries()
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build();


    DataReadResult dataReadResult = Fitness.HistoryApi.readData(mGoogleApiClient, readRequest).await(0, TimeUnit.MINUTES);
    DataSet dataSet = dataReadResult.getDataSet(DataType.TYPE_HEART_RATE_BPM);
    showDataSet(dataSet);
    displayBpmDataForToday();
}
private void showDataSet(DataSet dataSet) {
    Log.e("History", "Data returned for Data type: " + dataSet.getDataType().getName());
    DateFormat dateFormat = getDateInstance();
    DateFormat timeFormat = DateFormat.getTimeInstance();

    for (DataPoint dp : dataSet.getDataPoints()) {
        Log.e("History", "Data point:");
        Log.e("History", "\tType: " + dp.getDataType().getName());
        Log.e("History", "\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
        Log.e("History", "\tEnd: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS)) + " " + timeFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS)));
        for(Field field : dp.getDataType().getFields()) {
            Log.e("History", "\tField: " + field.getName() + " Value: " + dp.getValue(field));
        }
    }
}
private void displayBpmDataForToday() {
    DailyTotalResult result = Fitness.HistoryApi.readDailyTotal( mGoogleApiClient, DataType.TYPE_HEART_RATE_BPM ).await(0, TimeUnit.MINUTES);
    showDataSet(result.getTotal());
}

展开
收起
几许相思几点泪 2019-12-05 15:39:29 488 0
0 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载