I would like to write a program using tilting functionality in android.
Is there any way to intercept it? What do I get back? a vector indicating the direction of the tilt?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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_ACCELEROMETERsensor 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 the. Have a look at the values array forSensor.TYPE_ORIENTATION
Sensor.TYPE_ORIENTATION. They are the tilt values you are looking for.hope that helps