从History api接收的步骤数据与Google Fit不匹配 [英] Steps Data receive from History api is not matched with google fit

查看:107
本文介绍了从History api接收的步骤数据与Google Fit不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在我的应用程序中计入Google适合的步数,因为我使用的是由Google提供的History api.我发现从历史API接收的步骤与Google Fit不匹配,即使我使用了Google提供的相同代码也是如此.下面是我的代码.

I want google fit steps count in my application, for that I am using History api, provided by google. I found that steps receive from history api is not matched with google fit even if i used same code provided by google. Below is my code.

  Calendar cal = Calendar.getInstance();
        Date now = new Date();
        cal.setTime(now);
        long endTime = cal.getTimeInMillis();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        long startTime = cal.getTimeInMillis();

        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_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
                .bucketByTime(1, TimeUnit.DAYS)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .build();

  Task<DataReadResponse> result = Fitness.getHistoryClient(getApplicationContext(),
                GoogleSignIn.getLastSignedInAccount(getApplicationContext())).readData(readRequest);

任何帮助将不胜感激,我长期以来一直困扰于此问题,甚至没有从Google找到任何合适的教程.

Any Help will be highly appreciated, I am stuck with this issue from long time and even not finding any proper tutorial from google.

推荐答案

请参见常见问题解答 ,从字面上解释了您要描述的行为.

see the FAQ, which explain the behavior quite literally, which you're descibing.

这可能是最接近的;假设设备上安装了最新的Play服务:

this is possibly the closest one can get; assuming the latest Play Services installed on device:

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();

除了TYPE_CALORIES_EXPENDED以外,其他基本相同.或者,您可以记录自己的会话-不仅仅是estimated_steps ,但具有唯一的会话标识符.

it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.

这篇关于从History api接收的步骤数据与Google Fit不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆