Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect shake event with cordova android?

I'm trying to detect shaking event using Cordova 2.2.0 for android devices. I found some question related to this topic but t's in native code for example this question and this question.

Does anyone knows how to detect this event using phonegap Cordova ? or I should write a plugin ?

like image 360
T.Baba Avatar asked Dec 10 '12 21:12

T.Baba


2 Answers

You can try shake.js. Ive been looking into it, but not implemented it. It looks promising.

like image 124
AzurGroup Avatar answered Sep 26 '22 15:09

AzurGroup


Use the accelerometer to store the previous values (x, y and z). Defining the thresholds (x,y,z) you can detect shaking if the different betwen the previosValues and the actual once (event.value[i] where i=x,y ans z) is higher than the thresholds.

You also can use the magnitude of the acceleration values (Acc=sqrt(x*x+y*y+z*z)) or the timestamp to obtain better results.

like image 37
nabrugir Avatar answered Sep 25 '22 15:09

nabrugir