我正在開發一個android應用程序,其中一個功能是將屏幕方向鎖定到風景,我想將此方向更改應用於手機中的所有android應用程序。我使用此代碼鎖定android屏幕方向到風景
private void lockScreenOrientation() {
if (!mScreenOrientationLocked) {
final int orientation = getResources().getConfiguration().orientation;
final int rotation = getWindowManager().getDefaultDisplay().getOrientation();
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
}
mScreenOrientationLocked = true;
}
}
private void unlockScreenOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
mScreenOrientationLocked = false;
}
但這是暫時的變化,那並不生效,所有的應用程序,沒有人知道的方式來鎖定方位適用於所有的應用程序?謝謝
這是一個猜測,但我相當確定不可能將所有應用程序鎖定到橫向。 – harism
看看這個應用程序,它的工作方式與我想要的一樣https://play.google.com/store/apps/details?id=com.devasque.rotationlocker&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5kZXZhc3F1ZS5yb3RhdGlvbmxvY2tlciJd – Ahmed
我同意你可能*不應該*能夠......但它顯然是可能的。我在Nexus 7上使用了一個名爲「Set Orientation」的應用程序,它可以強制系統進入任何特定的方向。 – kcoppock