I am working on an Android app, for which I would like the user to be able to press a button which either enables or disables auto-rotate. How can I do this with an Intent? I'd imagine I would somehow need to change ACCELEROMETER_ROTATION to 0 or 1, but I don't know how to do this precisely. I hope maybe one of you guys can help me out!
Asked
Active
Viewed 5,071 times
1 Answers
9
You can toggle Rotation ON/OFF using ACCELEROMETER_ROTATION as :
if (android.provider.Settings.System.getInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0) == 1){
android.provider.Settings.System.putInt(getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0);
Toast.makeText(Rotation.this, "Rotation OFF", Toast.LENGTH_SHORT).show();
}
else{
android.provider.Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
Toast.makeText(Rotation.this, "Rotation ON", Toast.LENGTH_SHORT).show();
}
and finally add android.permission.WRITE_SETTINGS
permission in Manifast

ρяσѕρєя K
- 132,198
- 53
- 198
- 213
-
Thank you very much for your response, but how do I use this in an intent? I can't use onClick in my app. – Zero Oct 13 '12 at 08:17
-
intent means tell more about what you want – ρяσѕρєя K Oct 13 '12 at 09:36
-
Note: starting from API 23 (Android M - 6.x) , you need to request the permission , as such: http://stackoverflow.com/a/32083622/878126 – android developer Sep 03 '16 at 13:02