For example, I started application then device is turned 90 degree by side.I want to detect this event for each planes on device.
The tachometer measures the instantaneous rotational speed, also called the tachometer, and is used as an operation index for devices whose rotational speed fluctuates.
getDefaultDisplay(); int rotation = display. getRotation();
If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.
Azimuth (degrees of rotation about the -z axis). This is the angle between the device's current compass direction and magnetic north. If the top edge of the device faces magnetic north, the azimuth is 0 degrees; if the top edge faces south, the azimuth is 180 degrees.
You can get the screen orientation (for example in your onResume() Method) like this:
private static final int ORIENTATION_0 = 0;
private static final int ORIENTATION_90 = 3;
private static final int ORIENTATION_270 = 1;
Display display = ((WindowManager)
getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenOrientation = display.getRotation();
switch (screenOrientation)
{
default:
case ORIENTATION_0: // Portrait
// do smth.
break;
case ORIENTATION_90: // Landscape right
// do smth.
break;
case ORIENTATION_270: // Landscape left
// do smth.
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With