-
Notifications
You must be signed in to change notification settings - Fork 68
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
getSteps return empty array #60
Comments
Hey, the docs' usage example is as follows:
Notice that the permissions access is
If not, can you share more of your code? Cheers, |
Actually I have changed my code to your example after I shared, I think it did not change but I will check more and let you know. By the way I thought that this APIs just get data from phone and let us get data through this package but as you mentioned, it only saves data after we let permission to write? Did I understand it right? Also in this case should we let app stay open to be able to write this data? |
No, there is no need to keep the app open. |
Thanks for your answers. After few days of trying actually IOS started to return some response from the API but android is still same. Here is some questions.
Do they mean some extra package, or these are some default packages normally available in android devices? |
Hi @losheredos
|
Still same for android, I mean what I can do I dont know. Here is the full code example which I use:
I tried date with different formats but nothing changes. Am I wrong in something? |
@losheredos Just a side note: in your function And this is my implementation of getting the steps of today and the previous 6 days. I find that using momentjs makes working with dates a lot easier.
|
@rlems I think you read it wrong maybe, because its written in documentation Set interval to decide how detailed the returned data is, set it to hour or minute otherwise it defaults to days. If I'm not wrong. |
@losheredos
This object is wrong: The docs give this example:
|
Ah yeah got it, right. But anyways I added this interval option later to check if it will make difference in results. It didn't make any difference. I will even check again and write here. Edit: Yeah checked again and results are same. |
Having the same issue. Getting empty array on emulator and real device. here is my implementation.
Am I missing something? Shouldn't it at least return 0 if no steps were recorded for the day? |
Hi @marlene89, |
So there was no data then I decided to try react-native-google-fit . There I could at least get array with source data and steps arrays(which was empty as well). But noticed that in that package there is method to start recording. After I started that method data was recorded and I could get steps of the same day. So maybe in this package there should be a method to record (or it does automatically and there is issue about it?) for android side of it. You may try the same steps as I did and check if you will be able to get something more @marlene89 |
@losheredos There is a method to subscribe to steps: Check the documentation for more info. |
@rlems yeah thanks for warning I missed it, but if this was the case for this issue probably this method could be in top section of methods.. |
@losheredos will def try your suggestion. I'll post results when I have them. thanks :) |
Hey, thought this might be related. if these methods return false (failed to subscribe) it probably means the app doesn't have the required permissions, because as of Android 10 I think, physical activity is defined as a sensitive permission and requires Android permissions to be granted. To solve this, use It can be used like this:
I'll try and open a PR to add this functionality. Hope this helps in the meantime |
@ibraude , Hello, I used the Fitness.subscribeToSteps() method when the app started,and I agree to step authorization |
Hey, |
Haha, it's my problem. The debug package I used for testing but it should be the release package. Now I use the Fitness.subscribeToActivity() method to determine whether it is authorized, and then use the react-native-permissions library to request the two permissions of ACTIVITY_RECOGNITION and ACCESS_FINE_LOCATION. Now I have the user’s Steps, Calories and Distance, thank you |
@cham1985 can you share your code , because i am still getting the empty array. |
Any progress on this @GuleriaAshish ? @cham1985 could you share your setup? For me it also doesn't work on Android. For some reason it shows only the first screen to choose your account for the permissions, but not the actual permissions questions. I gave more details in this thread |
Ugh, never mind right after posting this it started working :D Seems like there's quite a delay in data syncing
This is my control flow (simplified): async function myFitness() {
const permissions = [
{
kind: Fitness.PermissionKinds.Steps,
access: Fitness.PermissionAccesses.Read,
},
];
const period = {
startDate: '2020-12-29T22:00:00.000Z',
endDate: '2021-01-05T21:59:59.999Z',
interval: 'days'
};
let isAuthorized = await Fitness.isAuthorized(permissions);
if (!isAuthorized) {
isAuthorized = await Fitness.requestPermissions(permissions);
if (!isAuthorized) {
return;
}
}
isAuthorized = await Fitness.subscribeToSteps();
if (!isAuthorized) {
return;
}
const trackedSteps = await Fitness.getSteps(period);
console.log(trackedSteps); // logs empty array
} |
but, if i get true from these methods I should be able to get some data, right? But i still get empty array here is my code [...]
here is my output: LOG permissions: [{"access": 0, "kind": 0}, {"access": 0, "kind": 2}, {"access": 1, "kind": 0}, {"access": 0, "kind": 1}, {"access": 1, "kind": 1}, {"access": 0, "kind": 4}, {"access": 1, "kind": 4}, {"access": 1, "kind": 2}] |
As @ibraude mentioned before I still get the empty array. It works on both android & IOS like authorizaiton etc. but when I get results of steps its just empty array. I thought it could be cuz of simulator but I test it in real device now, looks same..
Permissions:
Can anyone help about it?
The text was updated successfully, but these errors were encountered: