question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getSteps return empty array

See original GitHub issue

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:

const permissions = [
          {
              kind: Fitness.PermissionKind.Step,
              access: Fitness.PermissionAccess.Read
          },
];

Can anyone help about it?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
ibraudecommented, Aug 31, 2020

Hey, thought this might be related. So to be able to record steps\activity on Google Fit you must call the Fitness.subscribeToSteps() or Fitness.subscribeToActivity().

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. (see https://developers.google.com/fit/android/authorization#requesting_android_permissions )

To solve this, use react-native-permissions to request for the ACTIVITY_RECOGNITION permission.

It can be used like this:

import {check, request, PERMISSIONS, RESULTS} from 'react-native-permissions';
import Fitness from '@ovalmoney/react-native-fitness';

const requestActivityPermission = async () => {
    try {
       const result = await check(PERMISSIONS.ANDROID.ACTIVITY_RECOGNITION)
                switch (result) {
                    case RESULTS.UNAVAILABLE:
                        console.log(
                            'This feature is not available (on this device / in this context)',
                        );
                        break;
                    case RESULTS.DENIED:
                        console.log(
                            'The permission has not been requested / is denied but requestable',
                        );
                        await request(PERMISSIONS.ANDROID.ACTIVITY_RECOGNITION)
                        break;
                    case RESULTS.GRANTED:
                        console.log('The permission is granted');
                        break;
                    case RESULTS.BLOCKED:
                        console.log('The permission is denied and not requestable anymore');
                        break;
                }
    } catch (err) {
        console.warn(err);
    }
};

// wherever you subscribe to steps or activity, add requestActivityPermission() if the method returns false
   const handleSubscribe = async () => {
        try{
            const subscribedToSteps = await  Fitness.subscribeToSteps()
                    if(subscribedToSteps){
                        console.log("subscribed to step counter")
                    } else {
                       await requestActivityPermission()
                    }
        } catch (e) {
            console.log(e)
        }
    }

I’ll try and open a PR to add this functionality.

Hope this helps in the meantime

1reaction
ipsipscommented, Jan 5, 2021

Ugh, never mind right after posting this it started working 😄 Seems like there’s quite a delay in data syncing

I’m having the same unexpected result: getSteps() yields an empty array. I’m trying to fetch tracked steps on Android Emulator without having Google Fit app installed. I am leveraging subscribeToSteps() method as documentation suggests. I am certain that I have some steps tracked in given period because I can see them on Google Fit app that I have installed on my physical phone and I can confirm that permissions are successfully granted since my emulated app appears in Google Fit settings under “Third-party apps with account access”.

I could swear it did work when I last worked on the project couple a weeks ago… Did Google change something on their end? @Francesco-Voto

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
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to get Steps Data, show's empty array - Bountysource
I'm having trouble getting steps data. I'm using the getDailyStepCountSamples function, but the results is returning an empty array instead.
Read more >
React Native HealthKit getDailyStepCountSamples returning ...
... getDailyStepCountSamples returning undefined or empty array ... Once I initiate HealthKit again, it will return 'undefined' AND log ...
Read more >
High-Level APIs — ADIOS2 2.8.3 documentation
Empty constructor, allows the use of open later in the code ... isLocalValue – true: local value (returned as GlobalArray), false: global value...
Read more >
Empty arrays | Practice Problems - HackerEarth
Java Solution for Empty Arrays ... return 1 + getSteps(n-1, a.slice(1), b.slice(1)); } else { a = rotateArray(a); return 1 + getSteps(n, a, ......
Read more >
Variable Types: Arrays And Tables - Dev Center - Electric Imp
local arrayOne = array(); // Array creator function, initially empty local arrayTwo ... Calling typeof on an array returns the string "array" ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found