apache / apache/cordova-plugin-device-motion
Fix for new phones running Android > 12
- Dominant language
- JavaScript
- Stars
- 75
- Forks
- 128
- PR merge metrics
- No merged PRs in 30d
Description
For some reason (my guess is that it is due to not calibrating the sensor) phones running android > 12 the sensor accuracy comes back as SensorManager.SENSOR_STATUS_ACCURACY_LOW.
This causes the shake detection to not work in the shake plugin due to the check in onSensorChanged in AccelListener.java
The following change fixes the issue and shake detection is now working great for me on all phones.
Change the line in plugins/cordova-plugin-device-motion/src/android/AccelListener.java:
if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
to
if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_LOW) {
My guess is that while this works there is a better fix since the device-motion plugin is apparently depreciated.
Contributor guide
Research direction
Start with plugins/cordova-plugin-device-motion/src/android/AccelListener.java and inspect the accuracy check in onSensorChanged. Verify how low sensor accuracy affects shake detection on Android versions above 12, then confirm that the resulting change restores detection without breaking supported devices; also check the plugin's deprecated status before proceeding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100