Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null object reference error on Android when authorizing for calories.active #194

Open
wongpeiyi opened this issue Dec 4, 2020 · 7 comments
Labels
googlefit-nosupport issue related to Google Fix, which is now unsupported

Comments

@wongpeiyi
Copy link

wongpeiyi commented Dec 4, 2020

Getting error message on Android only

Attempt to invoke virtual method 'java.lang.String com.google.android.gms.fitness.data.DataType.zzm()' on a null object reference

when running:

navigator.health.requestAuthorization(['calories.active'], () => {}, (e) => console.error(e))

It doesn't happen when authorizing for just calories or basal:

navigator.health.requestAuthorization(['calories', 'calories.basal'], () => console.log('ok'), (e) => console.error(e))
// ok

I suppose I could manually calculate active using the other two, but would be great if anyone knows what is happening here

@forno
Copy link

forno commented Feb 2, 2021

I got same error with "date_of_birth" or "gender" on requestAuthorization.
They are invoke this issue too.

@dariosalvi78
Copy link
Owner

I have removed date_of_birth and gender from Android in the latest version of the plugin because they were not share

@forno
Copy link

forno commented Feb 2, 2021

@dariosalvi78 Thank you for your information.
I remove them on my app, then working now.

@wongpeiyi
Copy link
Author

@dariosalvi78 do you have comments on the original issue or do you require more information?

@dariosalvi78
Copy link
Owner

@wongpeiyi I still need to look into it. There may be a bug somewhere in the java code. Happy to receive pull requests if you manage to spot it before I do!

@fdmartins
Copy link

fdmartins commented May 28, 2021

Hi, there is a little confusion and a bug in android / healthy.js

datatype calories.active not exists for android, this is calculed using basal calories and total calories. So, you need request permission for 'calories.basal' and 'calories'... and NOT for 'calories.active' (you need use a conditional for ios version..)

for queryAggregated you can use 'calories.active' for both OS versions.

In healthy.js you need insert retval = retval[0]; near line 99, check code below:

navigator.health.queryAggregated(opts, function(retval){
//and remove the basal
retval = retval[0]; // << INSERT THIS LINE

retval.value -= basal_ms * (retval.endDate.getTime() - retval.startDate.getTime());
//although it shouldn't happen....
if(retval.value <0) retval.value = 0;
onSuccess(retval);

@dariosalvi78 thank you for this plugin!

@juanmaldonadodev
Copy link

@fdmartins That fix is not valid.
#295
You have an array as result because you added in the params the attribute:
bucket: 'day' So you need to iterate.

Adittionaly take into account that basal_ms can be 0 if the user have not changed age or height during the last year.

@dariosalvi78 dariosalvi78 added the googlefit-nosupport issue related to Google Fix, which is now unsupported label Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
googlefit-nosupport issue related to Google Fix, which is now unsupported
Projects
None yet
Development

No branches or pull requests

5 participants