Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Auto-Rotate Enabled/Disabled Android

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!

like image 597
Zero Avatar asked Jun 14 '26 05:06

Zero


1 Answers

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

like image 79
ρяσѕρєя K Avatar answered Jun 16 '26 21:06

ρяσѕρєя K