为全设备颤振Android 11保持方向更改



使用以下代码,我可以在应用程序中更改设备的方向

void rotate(orientation) {
if (!_isEnabled) return;
var property = DeviceOrientation.landscapeRight;
switch (orientation) {
case "Portrait":
property = DeviceOrientation.portraitUp;
break;
case "Reverse Portrait":
property = DeviceOrientation.portraitDown;
break;
case "Landscape Left":
property = DeviceOrientation.landscapeLeft;
break;
case "Landscape Right":
property = DeviceOrientation.landscapeRight;
break;
}
setState(() {
SystemChrome.setPreferredOrientations([property]);
});
}

但是,如果我退出应用程序并切换到其他应用程序,方向将更改为默认的纵向。

即使按下主页按钮也会默认方向。

我正在努力使整个设备的方向保持固定。

我在Google Play Store上发现一款应用程序可以运行到Android 10。从安卓11来说,它不起作用。

我使用的是安卓11和MIUI 12.5.5 的小米Redmi 9 Power

如何保持整个设备的方向固定?

你不能也不应该。安卓系统已经有了系统级定向配置,用户可以选择固定定向。当您的应用进入后台时,您的权限将终止。其他一些应用程序希望以水平方式播放视频,所以它会一直播放,而你的应用程序与此无关。启动器通常只支持纵向,永远不会以水平方式显示,因为它不方便用户。