ScreenOrientation

For keep the device in fixed orientation

-> Using Manifest: Define screen orientation in activity tag.

Example:

 

-> Using java code:
In manifest need to define the configurationChanges as orientation/screensize
In Activity override the onConfigurationChanged method.
Example:

 @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            Toast.makeText(this, "Current screen orientation is portrait", Toast.LENGTH_SHORT).show();
        }
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "Current screen orientation is Landscape", Toast.LENGTH_SHORT).show();
        }
//        If we want to set screen orientation to portrait or landscape
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
Advertisements

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