I'm trying to hook up some functionality with the "shake" event. I used the tutorials here:
http://www.vogella.com/articles/AndroidSensor/article.html
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/os/Sensors.html
I'm testing with OpenIntents' SensorSimulator. I am able to connect the emulator to the SensorSimulator. When I move the device in the Simulator, the accelerometer readings on the emulator exactly mirror the simulator's.
In my code, I've added some log statements like:
public class ShakeEventListener implements SensorEventListener {
private void getAccelerometer(SensorEvent event) {
float[] values = event.values;
// Movement
float x = values[0];
float y = values[1];
float z = values[2];
float accelationSquareRoot = (x * x + y * y + z * z)
/ (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();
Log.i("onSensorChanged", "accelationSquareRoot: " + accelationSquareRoot);
if (accelationSquareRoot >= 2) //
{
if (actualTime - lastUpdate < 200) {
return;
}
lastUpdate = actualTime;
// Shake Detected
Log.i("onSensorChanged", "Shakie Shakie!");
}
}
public void onSensorChanged(SensorEvent se) {
Log.d("onSensorChanged", "X: " + se.values[SensorManager.DATA_X] +
" Y: " + se.values[SensorManager.DATA_Y] +
" Z: " + se.values[SensorManager.DATA_Z]);
if (se.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
getAccelerometer(se);
}
}
}
The output in log cat doesn't seem to change if I move the device in the simulator. It's always showing these readings (reading keeps updating a bunch of times every minute, but they're always the same):
05-22 15:09:07.717: I/onSensorChanged(686): accelationSquareRoot: 1.0006835
05-22 15:09:08.518: D/onSensorChanged(686): X: 0.0 Y: 9.77622 Z: 0.813417
05-22 15:09:08.518: I/onSensorChanged(686): accelationSquareRoot: 1.0006835
I tried the APIDemos
sample sensors.java
but that's also registering the same behavior. What could I be missing?