Pedometer Module: Android - watchStepCount does not update - Permission is not being requested correctly.
See original GitHub issueSummary
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:
- Created 2 years ago
- Reactions:1
- Comments:17 (2 by maintainers)
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 .
Further updates from testing, since I am using
eas build
over the classicexpo build
which gives me access to theconfig-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.
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 returnsgranted
even when the permission is denied on the application level.