Android + Google Fit数据上传:错误5002-DataType的名称与软件包名称不匹配

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

在应用程序中,我们将用户活动数据像这样上载到Google Fit:

   Fitness.getSessionsClient(context, GoogleSignIn.getLastSignedInAccount(context))
                            .insertSession(((SessionInsertRequest) object))
                            .addOnSuccessListener(new OnSuccessListener<Void>() {
                                @Override
                                public void onSuccess(Void aVoid) {
                                    // At this point, the session has been inserted and can be read.
                                    if (BuildConfig.DEBUG) {
                                        Log.i(TAG, "Session insert was successful!");
                                    }
                                     //more success handling
                                }
                            })
                            .addOnFailureListener(new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {

                                    if (BuildConfig.DEBUG) {
                                        Log.w(TAG, "There was a problem inserting the session: " + e.toString()+ "\n"+ e.getLocalizedMessage());
                                    }
                                    //more error handling
                                    }
                                }
                            });

直到大约2019年9月4日,它的工作状况都很好。

然后,Google在创建SessionInsertRequest时似乎已更改了某些内容,从而导致以下警告:>

App com.foo.bar无法访问请求中的数据类型

并且在onFailureListener(...)中,我们收到以下消息:

插入会话时出现问题:com.google.android.gms.common.api.ApiException:5002:DataType的名称与包名称不匹配。

数据类型未更改。当要求用户授予上传权限时,会要求他们:

   private FitnessOptions getFitnessSignInOptions(OAuthType type) {

    switch (type) {

        case Activity:
            return FitnessOptions.builder()
                    .addDataType(DataType.TYPE_LOCATION_SAMPLE, FitnessOptions.ACCESS_WRITE)
                    .addDataType(DataType.TYPE_CALORIES_EXPENDED, FitnessOptions.ACCESS_WRITE)
                    .build();
    }
}

并在像这样的数据源中创建:

 DataSource  locationDataSource = new DataSource.Builder()
            .setAppPackageName(packageName)
            .setDataType(DataType.TYPE_LOCATION_SAMPLE)
            .setName(uniqueIdentifier + "-locations")
            .setType(DataSource.TYPE_RAW)
            .build();

类似于Google sample显示。

我们忽略设置数据源的名称还是使用setName(packageName)都没有关系。同样使用setStreamName(packageName)不能解决问题。其他人有这个问题或类似问题吗?

谢谢

罗伯特

在应用程序中,我们将用户活动数据上传到Google Fit,如下所示:Fitness.getSessionsClient(context,GoogleSignIn.getLastSignedInAccount(context)).insertSession((((...

android google-fit
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.