Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I.E.

android:configChanges='??'

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

like image 905
SagiLow Avatar asked Apr 22 '13 14:04

SagiLow


1 Answers

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
        }
};
like image 107
stinepike Avatar answered Sep 22 '22 00:09

stinepike