Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Andrei Ropotica
@andreiropotica
I do not follow, why is it related to retreving distance and calories, do I have to request more app permissions? I have added all the gcloud fit api read permissions available...
Andrei Ropotica
@andreiropotica
is there any way to see a more detailed error? like a cause or a call stack?
Andrei Ropotica
@andreiropotica
image.png
Here are all my scopes that I have selected:
image.png
Dario Salvi
@dariosalvi78
activity retrieves the activity segment data type (https://developers.google.com/fit/datatypes/activity#android), this used to be combined with sleep, but now they are splitting it. In my experience, depending also on the app that writes the data you can still find sleep inside activity.
In addition, the plugin estimates distance and calories for each activity, so these are needed as well.
In the future, I want to a) clearly split activity and sleep in the plugin and b) make calories and distance per activity optional, but for now it's like this.
As for more logging, you can check with logcat, but I doubt you will get anything more detailed...
Andrei Ropotica
@andreiropotica
So in other words, untill you can finish splitting activity I cannot do anything more to get my app to import fit.activity data?
northy55
@northy55

Hi Dario,
first of all, thank you for this awesome pugin! I do have one issue and I hope someone has already encountered it.
When querying steps for the past month, I receive duplicated days on 31/10. Data is then out of sync (values are set with 1-day offset).
I assume the issue accrues due to daylight savings time change on that day.

would appreciate any idea on how to fix this :)
data.png

Dario Salvi
@dariosalvi78
@andreiropotica no, you can use the plugin, you just need to make sure you get authorization for the right scopes.
Dario Salvi
@dariosalvi78
@northy55 some similar issues have already been reported already for Google Fit. There's not much this plugin can do about it.
Andrei Ropotica
@andreiropotica
@dariosalvi78 I have added all the read scopes in Google Cloud Console, but the navigator.health.query('{"startDate":"2020-04-30T21:00:00.000Z","endDate":"2020-05-31T21:00:00.000Z","dataType":"activity"}', function(success){}... keeps failing... Am I missing a permission in the app? Or is it another scope required that is not related to Fit API?
Dario Salvi
@dariosalvi78
app permissions should be taken care by the plugin, scopes must managed by you. I really don't know how to help I'm sorry. My suggestion is to start the process from the scratch, maybe you have missed a little detail somewhere. I feel your pain...
John Green
@JohnGre17555169_twitter
Hey! I've been facing an issue with the oxygen_saturation data type on android, I've searched around and you've stated that you've added it, but I'm getting the message "Attempt to invoke virtual method 'java.lang.String com.google.android.gms.fitness.data.DataType.zzk()' on a null object reference". The same issue happens when using vo2max
Andrei Ropotica
@andreiropotica
Whell I tried and added all scopes and I still get the error... what part of the process should I check? I have no more ideeas... my app was woking than it stopped... on the Activity related calls, HR, BP, W, H, are ok... any pinpoint would be helpfull...
Dario Salvi
@dariosalvi78
vo2_max is not supported on Android yet (but contributions are welcome)
@andreiropotica I'm out of ideas as well. I am not working on this plugin right now, but when I get back to it I will definitely check activity as one of the first things, as I also need it in my apps. Can't give you a time range right now though...
John Green
@JohnGre17555169_twitter
@dariosalvi78 Ah I see, how would I go about implementing it then? Is it possible to get the data and display it on my app like blood glucose, or is that not a possibility?
Dario Salvi
@dariosalvi78
@JohnGre17555169_twitter I'm afraid that Google Fit doesn't have VO2 Max, but check it yourself: https://developers.google.com/fit/datatypes
John Green
@JohnGre17555169_twitter

Sorry I meant for the oxygen saturation value, like when I wanted to display the blood glucose, I used your implementation of

navigator.health.query({
startDate: new Date(new Date().getTime() - 3 24 60 60 1000), // three days ago
endDate: new Date(), // now
dataType: 'height',
limit: 1000
}, successCallback, errorCallback)

Am wondering how I'd get it to work for oxygen saturation, cuz for some reason it's not giving me the above error fo null object reference

Dario Salvi
@dariosalvi78
maybe there's a bug but I don't know where, the code is pretty straightforward: datapoint.getValue(HealthFields.FIELD_OXYGEN_SATURATION).asFloat(); the only reason I can think about is that getValue() returns a null.
in that case you can try adding a further check in the java code: if (datapoint.getValue(HealthFields.FIELD_OXYGEN_SATURATION) != null) ...
but then I don't explain why would a null datapoint be stored at all, what for?
OK, I think I have an answer, the oxygen saturation has more than field, including an average, see https://developers.google.com/android/reference/com/google/android/gms/fitness/data/HealthFields
maybe that datapoint contains one of the other saturations...
this is easy to fix, you can try yourself if you're up for the challenge
Dario Salvi
@dariosalvi78
something like:
else if (dt.equals(HealthDataTypes.TYPE_OXYGEN_SATURATION)) {
   float oxysat;
   if (datapoint.getValue(HealthFields.FIELD_OXYGEN_SATURATION) != null)
      oxysat = datapoint.getValue(HealthFields.FIELD_OXYGEN_SATURATION).asFloat();
   else if (datapoint.getValue(FIELD_OXYGEN_SATURATION_AVERAGE) != null)
      oxysat = datapoint.getValue(FIELD_OXYGEN_SATURATION_AVERAGE).asFloat();
   obj.put("value", oxysat);
   obj.put("unit", "%");

   // get also max and min if available:
   if (datapoint.getValue(FIELD_OXYGEN_SATURATION_MAX) != null)
      obj.put("max", datapoint.getValue(FIELD_OXYGEN_SATURATION_MAX).asFloat());
   if (datapoint.getValue(FIELD_OXYGEN_SATURATION_MIN) != null)
      obj.put("min", datapoint.getValue(FIELD_OXYGEN_SATURATION_MIN).asFloat());
}
you can replace lines 657 - 661 of HealthPlugin.java to the ones here above
if they work, you can send me a pull request, or I can change the lines myself
@JohnGre17555169_twitter let me know!
Andrei Ropotica
@andreiropotica
@dariosalvi78 Ok, thank you very much for all your ideas, sugestions (on my issues), replys and hard work you do on the plugin, it helpes me a lot! :-D Looking forward to your updates, when you will have the time :-) Best wishes! Andrei
John Green
@JohnGre17555169_twitter
@dariosalvi78 Hey sorry for the late reply, seems like it still doesn't work, I added the code you sent but still facing the same error message, have you tried it on your end?
Dario Salvi
@dariosalvi78
thanks for trying. No I haven't tried on my hand and I cannot try it because I don't have the same data that you have. You will probably need to open Android Studio and debug the code to see what's inside those data points.
by the way, what app is writing those values that you cannot read?
noktilux
@noktilux

Hoping someone can help with a problem I can not solve with requesting heart rate on Android.

This is the Google oAuth "interface" I get on a phone (tried both Android 6 and 11) when asking for heart rate...

alt

Then this...

alt

After going through that, when I look at what's been granted, these are permissions for the app as shown in Fit:

alt

Permissions also confirmed by looking in settings/apps...

alt

Yet this is the error message I get back in my test app:

alt

No issues with steps or anything else. Only heart rate. i have gone over my Google cloud config dozens of times and tried jsut about everything. Hoping someone has been through something similar and can share their experience.

Dario, is there any way to get more debugging details beyond that error message? The key here is to figure out why Google thinks consent has not been given, when it seems it has. Note, I have followed all the instructions: app is in test mode, test users specified, scopes defined etc. Clearly it is asking for permission.
noktilux
@noktilux
I also made a regular web-based test version of this (using GAPI) and it differs from SDK in that it explicitly asks for "heart rate" permission, not just body sensors. Why Google are inconsistent is baffling. Anyhow, for what it's worth, the GAPI request does work, but only in browser-based interface (or PWA), not in cordova/android.
Dario Salvi
@dariosalvi78
@noktilux I would suggest to try with a new user. Also check which APIs the current user has authorized at https://myaccount.google.com/security
these are the ones related to the FIT APIs, the local permissions are related to giving access to sensors, but are a requirement for later giving access to the FIT APIs. In other words: FIT API authorization and local app permissions are 2 separate things and treated separately.
image.png
this is what I see on my user:
as you can see there is a specific item for heart rate
also, make sure you are using a recent version of cordova android (I used the latest) as it can affect the version of the Google APIs that you can use.
Dario Salvi
@dariosalvi78
my final suggestion: start everything from the scratch, new app (with latest cordova and android platform), latest version of the plugin (0.2.3), new Google cloud project, add ALL scopes in testing mode (remove unused scopes later), possibly use a pristine Google account as test user and use a phone (real phone, no emulator) with recent version of Android (10 or higher?).
For testing, you can use the default cordova app (but with changed app ID), then open the JS console with chrome://inspect and launch the commands from there.
Once you have your test app working, you can go back to your app and see what is missing.
Good luck! 🤞
noktilux
@noktilux

@dariosalvi78 I looked at the security settings and heart rate not showing up -- see here:

alt

Are you able to show me a screen shot of what OAuth asks you when you run your app? This is all I get (when asking only for heart rate):

alt

As you can see, no reference to heart rate at all.

These are the cordova versions on my current computer:

$> cordova -v ...
9.0.0 (cordova-lib@9.0.1)

$> cordova platform ls ...
Installed platforms:
android 8.1.0

These are both 1 version behind current, do I will try the latest BUT have to upgrade my OS first (or get my mother's computer ;-)

northy55
@northy55
Hey @dariosalvi78, have you encountered any issues with iOS health privacy screen settings? After authorizing and getting the steps data correctly, visiting health settings -> Data Access & Devices -> My app -> results in blank screen only. No way for users to check/change permissions 🧐Im using capacitor without ionic framework & its seems the issue accures on iOS 15+. Thanks in advance 🙏
Dario Salvi
@dariosalvi78
@northy55 it's the first time I hear it! Looks like a bug on iOS...