The main thing to get your head around it the concept of a listener.
In Android there isn't a method called getXtilt(), getYtilt() etc to get the orientation.
Instead you need to create a listener which you register with the system.
See the onSensorChanged(SensorEvent event) method? The Android system will invoke that method every time the sensor changes (which is very frequently). In this case it will be the TYPE_ACCELEROMETER sensor readings you will be receiving.
So when you get the SensorEvent 'event' have a look at the event.values[] array. It will contain the sensor readings. In the example code in the Android doc they register the Sensor.TYPE_ACCELEROMETER. You should register the
Sensor.TYPE_ORIENTATION. Have a look at the values array for
Sensor.TYPE_ORIENTATION. They are the tilt values you are looking for.
hope that helps
0
JoxTraex
On
Sounds like you would have to use the Accelerometer and interpret the values and then make a decision based on them. Look up SensorEventListener and it should get you in the right direction.
The main thing to get your head around it the concept of a listener. In Android there isn't a method called
getXtilt()
,getYtilt()
etc to get the orientation. Instead you need to create a listener which you register with the system.Look at this.
See the
onSensorChanged(SensorEvent event)
method? The Android system will invoke that method every time the sensor changes (which is very frequently). In this case it will be theTYPE_ACCELEROMETER
sensor readings you will be receiving.So when you get the SensorEvent 'event' have a look at the
event.values[]
array. It will contain the sensor readings. In the example code in the Android doc they register theSensor.TYPE_ACCELEROMETER
. You should register theSensor.TYPE_ORIENTATION
. Have a look at the values array forSensor.TYPE_ORIENTATION
. They are the tilt values you are looking for.hope that helps