获取手机的实际方向
我需要确定运行我的应用程序的手机的实际方向,但我找不到任何方法来做到这一点。我找到了“getRequestedOrientation”函数,但它只检索“setRequestedOrientation”函数设置的方向。
在我的应用程序中,我让手机根据其物理方向选择方向。我需要根据结果进行一些定制。
我该怎么办?
预先感谢您花时间帮助我。
I need to determine the actual orientation of the phone which is running my app and I can't find any way to do it. I have found the "getRequestedOrientation" function but it only retrieves the orientation set by the "setRequestedOrientation" function.
In my app, I let the phone choose the orientation according to it's physical orientation. And I have some customizing to do depending on the result.
How can I do?
Thanks in advance for the time you will spend trying to help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据这两个问题:
您可以使用:
Activity.getResources().getConfiguration().orientation
然而,根据第二个问题的评论,该值仅返回横向
或肖像。如果您还需要反向定向,我建议查询加速度计
值来检测差异。不过我对Android不太熟悉
加速度计足以建议如何准确地做到这一点。
According to these two questions:
you can use:
Activity.getResources().getConfiguration().orientation
According to the comment on the second question, however, this value returns only landscape
or portrait. If you need reverse orientation as well, I would suggest querying the accelerometer
values to detect the difference. However, I'm not familiar with Android and
accelerometers enough to suggest how to do so exactly.
使用 getRotation()
Use getRotation()
确实是为了获取当前的方向。
Its really to get the current orientation.
请参阅此、这个, 和 这个 stackoverflow 问题。它们都涉及如何获取 Android 手机方向,第二个包括 Android 指南针和方向系统如何工作的详细说明。
See this, this, and this stackoverflow question. They all address how to get the Android phone orientation and the second one includes a detailed explanation of how the Android compass and orientation system works.