问题
In an app we upload user activity data to Google Fit like this :
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
}
}
});
This was working fine until approx sep 4 2019.
Then Google seemed to have changed something resulting in the following warning when creating the SessionInsertRequest
App com.foo.bar does not have access to data types in request
and in onFailureListener(...) we get the following message:
There was a problem inserting the session: com.google.android.gms.common.api.ApiException: 5002: DataType's name does not match package name.
DataTypes were not changed. They are requested when the user is asked to give permission to upload :
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();
}
}
and created in a DataSource like :
DataSource locationDataSource = new DataSource.Builder()
.setAppPackageName(packageName)
.setDataType(DataType.TYPE_LOCATION_SAMPLE)
.setName(uniqueIdentifier + "-locations")
.setType(DataSource.TYPE_RAW)
.build();
similar as the Google sample shows.
It does not matter if we omit setting the name of the dataSource or using setName(packageName). Also using setStreamName(packageName) instead does not resolve the issue. Anybody else having this or a similar issue ?
Thank you
Robert
回答1:
I wonder if the issue is related to the use of GoogleSignIn.getLastSignedInAccount. Apparently in the new version of the library this is not liked. Using GoogleSignIn.getAccountForExtension should do the trick. It worked for my issue with locations
回答2:
I believe that you may have provided an invalid google-services.json file or at least one that is not compatible with the one used when you acquired permission from the user to use Google Fit. I had the same issue: when I uploaded the new version of my app on top of the one downloaded from Google Play, it gave this error. It did not happen if instead I installed the new version of the app from scratch. Regenerating the google-services.json file on Firebase and giving it to the new version of the app solved the issue. Now I can upload the app on top of the existing one and I do not get this error any more. Note however that before I did not have Firebase enabled so it is possible that Google does not allow any more using google-services.json that is not generated via Firebase
来源:https://stackoverflow.com/questions/57855759/android-google-fit-data-upload-error-5002-datatypes-name-does-not-match-p