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.

Pedometer Module: Android - watchStepCount does not update - Permission is not being requested correctly.

See original GitHub issue

Summary

Expected behaviour:

Value of stepCount should increase when device is physically moved. Walking with the device in a short distance (e.g., around a 15m^2 room) should trigger the step count to update as per its subscription.

Actual behaviour:

Permission will state granted. However, stepCount will not increase. Calling Pedometer.requestPermissionAsync() will return granted.

Additional notes:

It seems like the only solution people have come up with is ejecting from Expo. I believe this is a worst-case scenario, and at the very least Expo docs should be updated to reflect incompatibility with Android.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

44

Environment

Run expo start Or view through provided snack.

Reproducible demo

https://snack.expo.dev/@humaan/android-pedometer-expo-sdk44

Run this snack on your physical device, or make a new project using the code for a very simple repro.

This is the code ripped straight from the documentation (minus the styles) and removed getStepCount as it is documented as not supported.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ahmad-crossplatformcommented, May 10, 2022

So in short we cannot have this in managed app right ? that is a bummer . it would be nice to have Permissions like as an expo module so developers could stay in their expo go zone .

2reactions
Jleeowlcommented, Apr 8, 2022

Further updates from testing, since I am using eas build over the classic expo build which gives me access to the config-plugins.

Specifically, referring to this section of the documentation, https://docs.expo.dev/guides/config-plugins/#modifying-the-androidmanifestxml

I managed to modify the AndroidManifest.xml to include the required permission tag (<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />) in the resulting Android build/package.

With that, I can now see the corresponding permission in the application settings, and manually enable it for my application. This results in the pedometer working as intended. a91d5b90-e923-48d5-bf86-60db121eeb29

However, as originally mentioned by @lqze. On the implementation level, Pedometer.requestPermissionAsync() does not seem to prompt the user for runtime permission as it should, and just returns granted even when the permission is denied on the application level.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pedometer - Expo Documentation
Indicates if user can be asked again for specific permission. If not, one should be directed to the Settings app in order to...
Read more >
Request app permissions - Android Developers
The basic principles for requesting permissions at runtime are as follows: Ask for a permission in context, when the user starts to interact...
Read more >
Android - My step counter is not working - what should I do?
Once you have updated the app, quit and restart it. Press the WeWard icon and hold it for a second or two ->...
Read more >
Request runtime permissions - Unity - Manual
The runtime permissions API requires Android version 6 (API level 23). ... Note: If the user previously checked the Do not ask me...
Read more >
I can't use step counter sensor - Stack Overflow
And here is my permissions. if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) == PackageManager.
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