I think what you're after is the difference in values between X (left
and right), Y (up and down), Z (toward you and away).
My code looks something like this:
public void onSensorChanged(SensorEvent event) {
long curTime = System.currentTimeMillis();
x = Math.abs(event.values[0]);
y = Math.abs(event.values[1]);
z = Math.abs(event.values[2]);
if((x+y+z) > ACCEL_THRESHOLD){
shakeCount++;
shakeLevel += (x+y+z);
if(shakeCount >= 3){
shakeCount = 0;
shakeLevel = 0;
}
if(shakeLevel > SHAKE_THRESHOLD){
// Do something because the phone has been shaken.
}
}
}
What I'm doing is looking for repetitive amounts of movement in any
direction, over a certain threshold, over time. You could break this
down into counts for X, Y, and Z rather then adding them all together
like I am. Then, just play with different thresholds that trigger when
you expect.
Brenton
On Jan 14, 2:33 pm, Hari Edo <[email protected]> wrote:
> What is your code giving you that's unsatisfactory?
>
> Depending on your definition of "shake", you could probably
> tell the difference between "side to side" vs "up and down"
> but you will likely get very inconsistent results if you try to
> distinguish "leftward" vs "rightward". Your hand often
> anticipates a little, moving left before a big rightward jerk.
> (Google "anticipation animation" for more.)
>
> On Jan 14, 6:27 am, TsEMaNN <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hello developers,
>
> > I have got a problem concerning the SensorListener. At the moment I
> > can already detect if the phone got shaken. Addtionally I now want to
> > detect in which direction the phone is shaken. Do you maybe know which
> > values I have to consider to detect this?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en