Skip to content

Orientation detection mode

The device orientation is retrieved and stored in the id variable. Its value is displayed with a ternary condition.

int orientation = getResources().getConfiguration().orientation;
Toast.makeText(
    getBaseContext(),
    orientation == Configuration.ORIENTATION_LANDSCAPE ? "LANDSCAPE":
    orientation == Configuration.ORIENTATION_PORTRAIT ? "PORTRAIT": "OTHER",
    Toast.LENGTH_LONG
).show();