Accelerometer sensor in android:
Accelerometer sensor android is used to detect the motion event in the android devices,using the android sensor manager.Here, is the simple steps to find the motion events in android.
1)Register the sensorListener in the starting of the activity
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(this, mAccelerometer , SensorManager.SENSOR_DELAY_NORMAL);
|
2)implements SensorEventListener with the Activity
3)get the x,y,z values from the onSensorChanged Event,
float x = event.values[0];
float y = event.values[1];
float z = event.values[2]; |
4)Finally,UnRegister the sensorListener when pause() the activity,
mSensorManager.unregisterListener(this); |
Screenshot:
No comments:
Post a Comment