Read Google Fit Data

Hello,

I’m trying to read data from Google Fit on my capacitor mobile app.

I have added Android permissions.

   <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
   <uses-permission android:name="android.permission.BODY_SENSORS" />

I have enabled Fitness API in GCP console.
I have created the Oauth consent screen.
I have added my android app with the SHA-1 from Play store.

But when the user is getting asked consent, select his gmail account and validate, I get a no access error.

Two reasons in my mind:

  • Android studio SHA-1 doesn’t match with Play Store SHa-1
  • I need to add the scopes in Google Auth Platform / Data access, but I get asked " Demo video: how will the scopes will be used?". Never heard anybody doing this.

What do you think could be the reason this doesn’t work ?

Thank you very much.

In the future, sharing some code will help others understand your problem better and provide more accurate advice. – How do I ask a good question? - Help Center - Stack Overflow

Thank you for your interest.

Yes I agree, it’s better with code, but I didn’t want to confuse anyone here with a long piece of code that is not really relevant.

My main problem is the access to Fitness API/Google Fit, everything around consent/authorization is not my own code.

As you can see in the two possible reasons, this is either a problem with SHA-1 or the need to get my app verified.

Thank you.

Have you double-checked the SHA-1 in GCP against the App signing certificate SHA-1 in the Google Play Console (under App integrity)?

What is the current publishing status of your OAuth consent screen, and have you completed the verification process if required for the scopes you’re using?

I double check the SHA-1 in GCP against the one in Play Console, yes, but I’m wondering that as I’m testing this in Android Studio, this doesn’t cause a mismatch between the SHA-1 in Play Console and the one in Android Studio.

I’m guessing that everytime I switch my computer, the SHA-1 in Android studio is different, what do you think ?

I also find it supprising we need to add scopes with a youtube video, I haven’t see this in the several researches I have made. What about your experience ? Do you had to record yourself talking about the scopes to get access to Google Fit data (even for a testing environment) ?

Thank you very much for taking the time to answer my questions.

Correct.

No never needed to use google fit data.

Are you sure you really want to use Google Fit? AFAIK Google Fit is deprecated and Google Play will not accept any new apps with Google Fit. New apps should use Google Health Connect instead.

I delete my post because I didn’t reply to you but instead created a new comment by mistake.

What I was saying was:

All my Android users currently only have Google Fit installed on their devices. Nobody asked about Google Health Connect. I’m aware it’s Google Fit is getting deprecated and I want to support both, but I’m not sure how. I don’t want to force users to move to Google Health Connect.

What’s your approach to this problem ?

We transitioned to Google Health Connect last year, because Google Fit was also a huge PITA. Most of our user’s devices were already new enough to come with Health Connect. Also some 3rd party fitness apps, which our users relied on (e.g. for their smartwatch) stopped using Google Fit and switched to Health Connect.

There’s actually a drawback using Health-Connect: Health Connect is just a data hub. Apps can store their data and read other apps data, if permission is given. Different to Apple Health, you don’t get any “basic” data, like steps. Users still need an app to count steps, which could be Google Fit, Samsung Health, or any of the 3rd party step counter apps.
That means, users need to install and configure Google Fit to store steps data in Health Connect.

AFAIK you app can use the Google Fit and Health Connect API in parallel. There is the cordova-health plugin, which we used with Google Fit. The plugin also switched to Health Connect some time ago.
We have developed our own capacitor plugin for Health Connect and Apple Health by now, but it only reads data and covers very few use-cases.

1 Like