setRequestedOrientation 更改全局系统方向首选项

发布于 2025-01-11 01:01:22 字数 313 浏览 7 评论 0原文

大家晚上好。

简单的问题

为什么

mActivity.setRequestedOrientation(force ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

要从设备的快速设置图标打开“自动旋转”? 似乎 setRequestedOrientation() 会全局更改系统首选项,无论名为 setRequestedOrientation 的活动是否正在运行。

good evening people.

Simple question

why

mActivity.setRequestedOrientation(force ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

turns 'auto rotate' from device's quick settings icon ON ?
seems like setRequestedOrientation() globally changes system preference regardless activity which called setRequestedOrientation is running or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2025-01-18 01:01:22

我敢打赌,它是由制造商修改的 Android 版本的一些附加“功能”或行为。检查来自不同制造商或至少不同 Android 版本的其他设备。你也可以尝试使用模拟器

我有一些带有干净Android版本的旧平板电脑,其陀螺仪/加速计已损坏,设备重置后只能工作几个小时。所以我禁用了自动旋转并在其上设置了固定的水平方向。仍然当我使用与您的类似代码强制纵向模式运行我的应用程序时,它将按预期以纵向模式显示,但是当我退出我的应用程序时,整个界面/以前的应用程序以水平方式运行 - 仍然没有启用自动旋转选项

I bet its some additional "feature" or behavior of your Android version modified by manufacturer. check on some other device from different manufacturer or at least different Android version. you can also try to use emulator

I have some old tablet with clean Android version, which have broken gyro/accelerometer, works only for few hours after device reset. so I've disabled auto-rotate and set fixed horizontal orientation on it. still when I run my app with similar code to yours forcing portrait mode then it will show in portrait mode as intended, but when I exit my app then whole interface/previous app runs in horizontal - still no auto-rotate option enabled

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文