I was using Sensor.TYPE_ORIENTATION
to determine current angle of device but TYPE_ORIENTATION
is deprecated on API version 8. In SensorManager manual it refers to getOrientation()
function in order to use TYPE_ORIENTATION
.
Here is my old code :
public void onSensorChanged(SensorEvent event) {
Log.d("debug","Sensor Changed");
if (event.sensor.getType()==Sensor.TYPE_ORIENTATION) {
Log.d("debug",Float.toString(event.values[0]));
float mAzimuth = event.values[0];
float mPitch = event.values[1];
float mRoll = event.values[2];
Log.d("debug","mAzimuth :"+Float.toString(mAzimuth));
Log.d("debug","mPitch :"+Float.toString(mPitch));
Log.d("debug","mRoll :"+Float.toString(mRoll));
}
}
I'm really confused about using getOrientation()
function, can anyone please show me an example how to get the angles?
You now use two sensors (ACCELEROMETER and MAGNETIC_FIELD) to get that information. See blog post for more detail.
Permissions:
Regarding your second question. When you are registering your sensor listeners, change your code to read: