leecrossley / cordova-plugin-shake

Cordova / PhoneGap Plugin to detect when a physical device performs a shake gesture
http://ilee.co.uk
92 stars 33 forks source link

Fix needed in cordova-plugin-device-motion for new phones #40

Open markalston opened 1 month ago

markalston commented 1 month ago

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 due to the check in onSensorChanged in AccelListener.java

The following change fixes the issue and shake detection is now working great for me.

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.