Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if device orientation is locked (Detect if auto-rotate is enabled/disabled)

How can I find out is device's screen orientation locked? I am using OrientationEventListener to trigger some actions inside my app which I would like to disable if user has his screen locked.

I know I can usually can orientation like this but how to find out is this locked orientation:

    int orientation = getResources().getConfiguration().orientation;

    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        // It's portrait
    } else {
        // It's landscape
    }
like image 238
Astagron Avatar asked Jan 06 '16 15:01

Astagron


1 Answers

Use this:

if (android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
        Toast.makeText(getApplicationContext(), "Auto Rotate is ON", Toast.LENGTH_SHORT).show();

    }
    else{
        Toast.makeText(getApplicationContext(), "Auto Rotate is OFF", Toast.LENGTH_SHORT).show();
    }
like image 107
AndroidMechanic - Viral Patel Avatar answered Oct 10 '22 02:10

AndroidMechanic - Viral Patel