On Sun, Jul 11, 2010 at 9:43 PM, Brad Gies <[email protected]> wrote: > Has anyone implemented an Android Shake Detector that works well on most > phones?
http://github.com/commonsguy/cw-advandroid/tree/master/Sensor/Shaker/ > I thought it would be fairly simple to implement but I keep getting false > results. Basically, what I'm doing is setting up a sensor Listener, checking > to make sure it is a SensorManager.SENSOR_ACCELEROMETER event, then only > checking the event if the last event I received was more than 50 > milliseconds ago (to try to reduce the amount of checking I do)... Then I > look for 3 "Shakes" within 4 seconds... A "Shake" to me being a speed > reading of over 1000 followed by a speed reading of less than 400 within 1 > second. If you are holding the phone in your hand, and are shaking it, you might think that the phone is constantly accelerating. It's not. As you swing your hand back and forth, the phone accelerates, decelerates, stops, accelerates in the opposite direction, decelerates, stops, etc. Hence, any single reading of the accelerometer may be low, even if you think you are actually shaking the phone. The algorithm I use allows you to define a ratio over gravity (e.g., 1.25f means 25% more than the force of Earth's gravity [implementations for non-Earth locations, such as the surface of the original Death Star, are left as an exercise for the reader]). It also allows you to define the "quiet time" (sub-threshold acceleration) necessary to consider a shake to have stopped (e.g., 500ms). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training...At Your Office: http://commonsware.com/training -- 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

