设置自动旋转启用/禁用Android

时间:2012-10-13 07:21:14

标签: android button android-intent rotation

我正在使用Android应用,我希望用户能够按下启用或禁用自动旋转的按钮。我怎么能用Intent做到这一点?我想我会以某种方式将ACCELEROMETER_ROTATION更改为0或1,但我不知道如何准确地做到这一点。我希望也许你们其中一个人可以帮助我!

1 个答案:

答案 0 :(得分:9)

您可以使用ACCELEROMETER_ROTATION将开启/关闭旋转为:

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();
    }

最后在Manifast中添加android.permission.WRITE_SETTINGS权限