Android 打开屏幕旋转

添加设置读写权限:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

判断是否屏幕旋转被关闭,如果关闭则打开:

// check whether the screen rotation works
    int flag = Settings.System.getInt(getContentResolver(),
        Settings.System.ACCELEROMETER_ROTATION, 0);
    if (0 == flag) {
      // open screen rotation and give user infomation alert
      Toast.makeText(getApplicationContext(), "open screen rotation",
          Toast.LENGTH_LONG).show();
      Settings.System.putInt(getContentResolver(),
          Settings.System.ACCELEROMETER_ROTATION, 1);

你可能感兴趣的:(Android 打开屏幕旋转)