特定时间的用户速度数据

问题描述

我应该怎么做才能在特定时间获取用户的速度数据?我订阅recordClient API就够了吗?

解决方法

您可以尝试从 Google Fit Git 存储库进行基本历史会话。 https://github.com/googlearchive/android-fit/blob/master/BasicHistorySessions/app/src/main/java/com/google/android/gms/fit/samples/basichistorysessions/MainActivity.java

// Build a session read request
        SessionReadRequest readRequest = new SessionReadRequest.Builder()
                .setTimeInterval(startTime,endTime,TimeUnit.MILLISECONDS)
                .read(DataType.TYPE_SPEED)
                .setSessionName(SAMPLE_SESSION_NAME)
                .build();


// Invoke the Sessions API to fetch the session with the query and wait for the result
                    // of the read request.
                    SessionReadResult sessionReadResult =
                            Fitness.SessionsApi.readSession(mClient,readRequest)
                                    .await(1,TimeUnit.MINUTES);

                    // Get a list of the sessions that match the criteria to check the result.
                    Log.i(TAG,"Session read was successful. Number of returned sessions is: "
                            + sessionReadResult.getSessions().size());
                    for (Session session : sessionReadResult.getSessions()) {
                        // Process the session
                        dumpSession(session);

                        // Process the data sets for this session
                        List<DataSet> dataSets = sessionReadResult.getDataSet(session);
                        for (DataSet dataSet : dataSets) {
                            dumpDataSet(dataSet);
                        }
                    }

有关会话的更多信息,请查看此链接 https://developers.google.com/fit/android/using-sessions#read_fitness_data_using_sessions