Google fit data与google fit应用不匹配,例如DataType.TYPE_WORKOUT_EXERCISE

问题描述 投票:0回答:1

我可以使用历史记录api读取google fit数据,但数据不返回或与官方的Google Fit应用不匹配

例如,当我读取Session DataType.TYPE_WORKOUT_EXERCISE时,只能读取标签和开始/结束日期时间,但是dataSet.getDataPoints()返回空数组,因此我无法读取step_count /卡路里/距离等。

public static void readSessionsApiAllSessions(Context context) {

        SessionReadRequest readRequest = readFitnessSession();

        Fitness.getSessionsClient(context , GoogleSignIn.getLastSignedInAccount(context))
                .readSession(readRequest)
                .addOnSuccessListener(new OnSuccessListener<SessionReadResponse>() {
                    @Override
                    public void onSuccess(SessionReadResponse sessionReadResponse) {
                        // Get a list of the sessions that match the criteria to check the result.
                        List<Session> sessions = sessionReadResponse.getSessions();
                        Log.i(TAG, "Session read was successful. Number of returned sessions is: "
                                + sessions.size());

                        for (Session session : sessions) {
                            // Process the session
                            dumpSession(session);

                            // Process the data sets for this session
                            List<DataSet> dataSets = sessionReadResponse.getDataSet(session);
                            for (DataSet dataSet : dataSets) {
                                dumpDataSet(dataSet);
                            }
                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.i(TAG, "Failed to read session");
                    }
                });

    }

    public static SessionReadRequest readFitnessSession() {
        Calendar cal = Calendar.getInstance();
        Date now = new Date();
        cal.setTime(now);
        long endTime = cal.getTimeInMillis();
        cal.add(Calendar.DAY_OF_YEAR, -2);
        long startTime = cal.getTimeInMillis();

        // Build a session read request
        SessionReadRequest readRequest = new SessionReadRequest.Builder()
                .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
                .read(DataType.TYPE_WORKOUT_EXERCISE)
                .readSessionsFromAllApps()
                .enableServerQueries()
                .build();
        // [END build_read_session_request]

        return readRequest;
    }
android google-fit google-fit-sdk
1个回答
0
投票

我正遇到同样的问题。我认为这是一个授权问题。.确保使用GoogleSignIn.getAccountForExtension并包含一组适用性选项-修复了一堆最近的问题,但仍为DataType.TYPE_WORKOUT_EXERCISE获取空数据集。我尚未能够迁移到Fitness v18-未正确授权。删除您帐户上的第三方应用访问权限,然后重试。.仍然不走运。

有人有新信息吗?

© www.soinside.com 2019 - 2024. All rights reserved.