Google Fit dataRead returns status TIMEOUT

怎甘沉沦 提交于 2019-12-11 11:31:33

问题


I am trying to get step data from Google Fit Api. I am able to successfully connect to the Api, however when I try to retrieve data using the Fitness.HistoryApi.readData() function, it always returns status TIMEOUT and no data.

Anyone have any idea what I am doing wrong? Thanks! Code below

private void requestHistory() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    long start = calendar.getTimeInMillis();

    //Google Fit Client connection happens elswhere
    if (mClient.isConnected) {
        DataReadRequest readRequest = new DataReadRequest.Builder()
            .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
            .bucketByTime(1, TimeUnit.DAYS)
            .setTimeRange(start, System.currentTimeMillis(), TimeUnit.MILLISECONDS)
            .enableServerQueries()
            .build();


        DataReadResult dataReadResult = Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);

        //HERE dataReadResult always has status TIMEOUT and no data
        if (dataReadResult.getBuckets().size() > 0) {
            //do some stuff
        }
    }
}

回答1:


I figured it out. Maybe it will help someone. I was doing this inside of an AsyncTask, and for some reason that caused it to timeout. Moving this logic outside of the AsyncTask's doInBackground method fixed the issue



来源:https://stackoverflow.com/questions/33898766/google-fit-dataread-returns-status-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!