For keep the device in fixed orientation

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



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

    public void onConfigurationChanged(Configuration 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

Leave a Reply

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

You are commenting using your 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