Reputation: 369
I am doing a demo in which when I move device like on top-left, top-right,top-center and bottom-right, bottom-left, bottom-center, center-right, center-left this type of movement I need to detect so that I am looking for accelerometer and gyroscope sensor. Am I going on the right track or not?
Do you have any demo or any link?
Upvotes: 0
Views: 1251
Reputation: 1210
Yes accelerometer would be a good option to detect the motion of the phone
You need to override the onSensorChange even in your activity in order to detect accelerometer values.
public void onSensorChange(SensorEvent sensorEvent) {
Sensor mySensor = sensorEvent.sensor;
if (mySensor.getType() == Sensor.TYPE_ACCELEROMETER) {
float x = sensorEvent.values[0];
float y = sensorEvent.values[1];
float z = sensorEvent.values[2];
}
}
Get started from here
Using the Accelerometer on Android
Also check out this page for a collection of android sensors library.
Upvotes: 2