[英]Set Auto-Rotate Enabled/Disabled Android
我正在開發一個Android應用程序,我希望用戶能夠按下啟用或禁用自動旋轉的按鈕。 我怎么能用Intent做到這一點? 我想我會以某種方式將ACCELEROMETER_ROTATION更改為0或1,但我不知道如何准確地做到這一點。 我希望也許你們中的一個人可以幫助我!
您可以使用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
權限
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.