2

我正在开发一个 Android 应用程序,我希望用户能够按下一个按钮来启用或禁用自动旋转。如何使用 Intent 执行此操作?我想我会以某种方式需要将 ACCELEROMETER_ROTATION 更改为 0 或 1,但我不知道如何精确地做到这一点。我希望也许你们中的一个可以帮助我!

4

1 回答 1

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

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

于 2012-10-13T07:27:16.893 回答