简体   繁体   中英

android Auto-Rotate configuration on change listener

I want to listen to 'Auto-Rotate' configuration change, not the device/system orientation, but to the toggle changes (on/off)
I believe i will have to sign up to configChange in the AndroidManifest and create a listener wherever i want but i'm not sure what is the correct config. IE

android:configChanges='??'

But maybe another way exists and not through the android:configChanges ...

you have to listen to Settings.System.ACCELEROMETER_ROTATION using a content observer.

To register the content observer

getContentResolver().registerContentObserver(Settings.System.getUriFor
(Settings.System.ACCELEROMETER_ROTATION),
true,rotationObserver );

And declare it here. The onChange method will be called when the rotation is changed.

private ContentObserver rotationObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
           Do your task
        }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM