Home > Android > How to know orientation of screen in android

How to know orientation of screen in android


Hi everyone, today I will show you how to know the orientation of screen in android.
In code below, show us know screen phone in land or portrait:

Configuration config = getResources().getConfiguration(); 
// Landscape
if(config.orientation == Configuration.ORIENTATION_LANDSCAPE) {      
   Toast toast = Toast.makeText(this, "Landscape", Toast.LENGTH_SHORT);     
   toast.show(); 
}  
// Portrait
else if (config.orientation == Configuration.ORIENTATION_PORTRAIT) {     
   Toast toast = Toast.makeText(this, "Portrait", Toast.LENGTH_SHORT);    
   toast.show(); 
}
 // Square
else if (config.orientation == Configuration.ORIENTATION_SQUARE) {    
   Toast toast = Toast.makeText(this, "Square", Toast.LENGTH_SHORT); 
    toast.show();
}
Categories: Android
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: