我正在开发一个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