I need to add a shake feature that will refresh my Android application.
All I find of documentation involves implementing the SensorListener
, but Eclipse tells me it's deprecated and suggest SensorEventListener
.
Anybody that has a nice guide to how I go about creating this shake controller
?
I am developing a motion-detection and shake-detection app for my university project.
Besides the original target of the application, I am splitting the library part (responsible for motion and shake detection) from the app. The code is free, available on SourceForge with the project name "BenderCatch". Documentation I am producing will be ready around mid-september. http://sf.net/projects/bendercatch
It uses a more precise way to detect shake: watches BOTH the difference of force between SensorEvents AND the oscillations present in X and Y axis when you perform a shake. It can even make a sound (or vibrate) on each oscillation of the shake.
Feel free to ask me more by e-mail at raffaele [at] terzigno [dot] com
I have written a small example for detecting vertical and horizontal shakes and showing a
Toast
.You should subscribe as a
SensorEventListene
r, and get theaccelerometer
data. once you have it, you should monitor for sudden change in direction (sign) of acceleration on a certain axis. it would be a good indication for the'shake'
movement.You might want to try open source tinybus. With it shake detection is as easy as this.
It uses seismic for shake detection.
Here is my code for shake gesture detection:
Add this in your activity:
...
in onCreate() add:
and:
You can use seismic. An example can be found here.