Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android I want to get rotation angle for device

For example, I started application then device is turned 90 degree by side.I want to detect this event for each planes on device.

like image 457
rookie.4ever Avatar asked Dec 09 '12 17:12

rookie.4ever


People also ask

How do you measure the rotation of a 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.

How do I know what orientation my Android phone is?

getDefaultDisplay(); int rotation = display. getRotation();

How do you handle rotation on Android?

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.

What is Azimuth in Android?

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.


1 Answers

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;
}
like image 60
Siggy Avatar answered Sep 21 '22 13:09

Siggy