gpt4 book ai didi

Android:activity.getResources().getConfiguration().orientation 在 Samsung galaxy 设备上返回错误值

转载 作者:行者123 更新时间:2023-11-29 01:04:11 25 4
gpt4 key购买 nike

对于我的 Android 应用程序,activity.getResources().getConfiguration().orientation 的返回值始终为 1 (ORIENTATION_PORTRAIT),即使设备处于横向模式也是如此。这种情况特别发生在 Samsung Galaxy 设备上。这导致我的 fragment 使用纵向布局而不是项目中存在的横向布局。有没有其他方法可以检查三星设备的方向?还有其他人面临同样的问题吗?

    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);

// Get device orientation
Configuration config = activity.getResources().getConfiguration();
mOrientation = config.orientation;

最佳答案

您不是第一个提示某些三星手机存在此缺陷的人: control orientation by sensor on Samsung devices 。如果你不关心 SCREEN_ORIENTATION_REVERSE_PORTRAIT 的情况,也许,对你来说SCREEN_ORIENTATION_SENSOR将比 SCREEN_ORIENTATION_FULL_SENSOR 工作得更好。

对于这家制造商所做的某些事情并不像您预期​​的那样,我并不感到惊讶。我相信你仍然可以使用 OrientationListener从加速度计中得出真实的设备方向,如 How to detect my screen orientation in portrait locked screen in android? .

关于Android:activity.getResources().getConfiguration().orientation 在 Samsung galaxy 设备上返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48777084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com