I am using OrientationEventListener() for detecting orientation change but it gives continuous values.I want only four values for each orientation i.e PORTRAIT,REVERSE_PORTRAIT,LANDSCAPE AND REVERSE_LANDSCAPE MODE.what should i do to get values only if orientation changes.My problem is i want to detect orientation when device quickly turns from LANDSCAPE MODE to REVERSE LANDSCAPE MODE.I want to call currentScreenOrientation() function only once when orientation changes but now it is calling it for every value between 0 to 359.
mOrientationEventListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int arg0) {
currentScreenOrientation();
}
};
if (mOrientationEventListener.canDetectOrientation()) {
Toast.makeText(this, "Can DetectOrientation", Toast.LENGTH_LONG)
.show();
mOrientationEventListener.enable();
} else {
Toast.makeText(this, "Can't DetectOrientation", Toast.LENGTH_LONG)
.show();
finish();
}
}
thanx in advance.