• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Am I motionless?

Claghorn

Android Enthusiast
If I want to use the accelerometer sensor to detect that I'm *not* moving, I assume the best way is to use a timer to notice that I haven't gotten an onSensorChanged() event in a while?

Or are the sensors so sensitive that something you might think was motionless is still getting onSensorChanged() events from time to time so that I should look at the amount of change to see if I think it is significant?
 
If I were you, I would:
  • register sensor data each, say, 0.1 seconds and put them to an array (array of vectors3D)
  • read last 15 values and check if they are "almost equivalent". i.e. each axis acceleration is in range of, for instance, -0.1 ~ +0.1 of the last one.
  • if yes, you are almost motionless.

Not sure about last 15 values or 0.1 interval, maybe you should set more or less, you'll find out after testing. Not sure about "almost" range either.
 
Just added test code to my app to put the acceleration values on the screen. They do constantly fluctuate down in the low digits, so I'll need to round up a bit and check for "significant" motion, not just any motion at all (that's what I see on my Nexus 5, anyway).
 
Now collect these values into an array and see what is the fluctuation range. Check if last 20 values lie in this range, if yes - the phone is not moving. If you don't move the phone, but it is detected as a motion, double the range.
 
Back
Top Bottom