Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if auto-rotate screen setting is ON/OFF in Android 4.0+

Tags:

java

android

I think each android device has an abitily to on/off auto-rotating function. Usually you can find it in settings->display->auto-rotate on/off. How can I read this setting state from my application? How can I access to this setting value? If you can share a code snipped i'd be very appreciate it.

like image 482
KennyPowers Avatar asked Jan 03 '14 11:01

KennyPowers


People also ask

How do you check if auto rotate is working?

Turn On Screen Rotation From Android SettingsLaunch the Settings app on your Android phone. Tap Display in the list of items. Turn on the option that says Auto-rotate screen.

Why can't I find auto rotate on my Android?

Swipe down from the top of the screen to open the Quick settings panel. Look for the screen orientation icon. Depending on your settings, you may need to look for the Portrait, Landscape, or Auto Rotate icon.

Why can't I find auto rotate in my settings?

If the screen rotation is already on try turning it off and then on again. To check this setting, you can swipe down from the top of the display. If it's not there, try going to Settings > Display > Screen rotation.


2 Answers

Hope this code snippet helps you out:-

@Override      
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);
    if (android.provider.Settings.System.getInt(getContentResolver(),
            Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
        Toast.makeText(getApplicationContext(), "Rotation ON", Toast.LENGTH_SHORT).show();

    }
    else{
        Toast.makeText(getApplicationContext(), "Rotation OFF", Toast.LENGTH_SHORT).show();
    }
    super.onCreate(savedInstanceState);
}
like image 86
Harshal Benake Avatar answered Sep 29 '22 05:09

Harshal Benake


Use the following code:

if (android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
    Toast.makeText(Rotation.this, "Rotation ON", Toast.LENGTH_SHORT).show();
} else {
    Toast.makeText(Rotation.this, "Rotation OFF", Toast.LENGTH_SHORT).show();
}
like image 36
Meenal Avatar answered Sep 29 '22 06:09

Meenal