7

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

SagiLow
  • 5,721
  • 9
  • 60
  • 115
  • This is the question ... what should i sign up for ... – SagiLow Apr 22 '13 at 14:59
  • http://stackoverflow.com/a/4435473/1620542 take a look at that, should be what you want – Eluvatar Apr 22 '13 at 15:01
  • Try this link https://www.google.co.in/search?q=android:configchanges – Sankar V Apr 22 '13 at 15:02
  • configChanges will only notify you when the rotation changes (among other things), you want to know when the Auto Rotate setting changes no? – Eluvatar Apr 22 '13 at 15:04
  • @Eluvatar , yes, you are right, it might be in another way ... i just thought it will be this way, Can you please expand how the first link should help ? i wasn't able to understand where the auto-rotate comes in.. – SagiLow Apr 22 '13 at 15:06
  • @sankarV , sorry it doesn't help, already tried it. – SagiLow Apr 22 '13 at 15:07
  • this should be more what you're looking for http://stackoverflow.com/a/7017516/1620542 you will need to tweak it to work for you but it should be fine, just remember that setting is in Accessibility. – Eluvatar Apr 22 '13 at 15:28
  • check my answer.. although it is downvoted by some one :( but my answer is what you wanted... it responds when the auto rotation button is clicke – stinepike Apr 22 '13 at 15:34

1 Answers1

14

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
        }
};
stinepike
  • 54,068
  • 14
  • 92
  • 112