I am developing a simple Shake function for my application and I am having a strange problem. When I test it on my Honor5x, it works like a charm, but when I tried to execute it on the Samsung S5, it is too sensitive. Is it possible that the accelerometer works differently on different devices? If so, is it possible that the change in condition depends on the accuracy of the device / accelerometer? Here is my code for detecting a Shake event:
gravity [0] = alpha * gravity [0] + (1 - alpha) * event.values ββ[0];
gravity [1] = alpha * gravity [1] + (1 - alpha) * event.values ββ[1];
float accX = event.values ββ[0] - gravity [0];
float accY = event.values ββ[1] - gravity [1];
float maxSpeed ββ= Math.max (accX, accY);
if (maxSpeed> SHAKE_THRESHOLD)
{
if (shakesInRow == 0) {
shakesInRow ++;
shakeTime = System.currentTimeMillis ();
} else {
if ((System.currentTimeMillis () - shakeTime) <SHAKE_TIME_DETECTOR) {
shakesInRow ++;
} else {
shakesInRow = 0;
shakeTime = 0;
return
}
if (shakesInRow> = SHAKE_IN_ROW) {
shakesInRow = 0;
runMainActivity ();
}
}
}
source share