添加設置讀寫權限:java
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
判斷是否屏幕旋轉被關閉,若是關閉則打開:android
// 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);