Reputation: 2077
I want to detect reverse landscape and portrait orientation. Configuration does not support ORIENTATION_REVERSE_LANDSCAPE
or ORIENTATION_REVERSE_PORTRAIT
.
I have also tried Activityinfo.ORIENTATION_REVERSE_PORTRAIT
but it's also not working.help me.
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
Log.e("On Config Change","LANDSCAPE");
}else{
Log.e("On Config Change","PORTRAIT");
}
Upvotes: 1
Views: 2988
Reputation: 411
I found that if your device has a magnetometer you can differentiate between landscape and reverse landscape by calculating the rotational attitude of the device (azimuth, pitch, and roll) using the SensorManager
methods getRotationMatrix()
and getOrientation()
. If the roll is positive, you're in reverse landscape (landscape right), and if the roll is negative you're in landscape (landscape left).
Similarly, you can use the pitch to differentiate between portrait and reverse portrait. If the pitch is positive, you're in reverse portrait, and if the pitch is negative you're in portrait.
If your device doesn't have a magnetometer, you can use the x-axis and y-axis values of the accelerometer to differentiate between landscape and reverse landscape. A negative x-axis value indicates reverse landscape (landscape right), and a positive value indicates landscape. Similarly, a negative y-axis value indicates reverse portrait, and a positive y-axis value indicates portrait.
Upvotes: 1