I have a problem connecting to the Google Fitness API from a WearOS device. I want to use the watch to record heart rate to Google Fit. I think I have some problem with permissions:
I build a FitnessOptions object, listing required datatypes. -
onCreate()
fitnessOptions = FitnessOptions.builder() .addDataType(DataType.TYPE_HEART_RATE_BPM, FitnessOptions.ACCESS_WRITE) .addDataType(DataType.TYPE_HEART_RATE_BPM, FitnessOptions.ACCESS_READ) .build();
I request permissions if needed, otherwise try to connect -
onResume()
if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions)) { Log.d(TAG, "Will request permissions."); GoogleSignIn.requestPermissions( this, // your activity GOOGLE_FIT_PERMISSIONS_REQUEST_CODE, GoogleSignIn.getLastSignedInAccount(this), fitnessOptions); } else { Log.d(TAG, "Will access google fit."); accessGoogleFit(); }
And here I have a problem: GoogleSignIn
starts an activity and asks me to log in, as expected. I choose account, which ends log in activity and resumes my activity. And I still don't have permissions, because it prompts me again to sign in.
In my manifest file:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
I use a similar process on phone and it works. Both apps (mobile and wear) are registered in the Google API Console, using the same OAuth2 credentials (is that a problem?).
Any pointers appreciated.