getRotation总是返回零 [英] getRotation always returns zero

查看:154
本文介绍了getRotation总是返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论

getRotation 总是返回零哪种方式屏幕导向。我跑2.3在真实设备上运行此。什么理由?

 显示显示=((窗口管理器)context.getSystemService(Context.WINDOW_SERVICE))getDefaultDisplay()。
 INT旋转= display.getRotation();


解决方案

如果该应用程序有一个UI和用户界面允许旋转getRotation才有效。有操作系统,可以prevent自动旋转的任何应用程序设置:

设置>显示>自动旋转屏幕

这已被启用。在我的设备,它被禁用。然而,在getRotation Android的文档不仅不能指出这一点,但即使给你getRotation将返回旋转即使没有UI的假设。你需要一个UI。这当然是类似的东西没有UI但需要知道该装置的用于具有无关的用户交互的目的的取向的服务的问题。就个人而言,我不断得到由谷歌雇用谁认为访问硬件功能应该总是需要某种UI业余程序员生气。这类问题已经突然出现​​在许多场合,就像有一个SurfaceView录制视频。

最后,显然不是要求一个应用程序getRotation搞清楚该设备是否被旋转0,90,180或270度。随着自动旋转屏幕关闭时,默认的相机应用仍然能够找出角度旋转,因此它不能从getRotation是,除非它是某种能够开启自动旋转屏幕的设置。

getRotation always returns zero regardless which way the screen is oriented. I'm running this on a real device running 2.3. Any reason why?

 Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
 int rotation = display.getRotation();

解决方案

getRotation will only work if the app has a UI and the UI is allowed to rotate. There is a setting for the operating system that can prevent any app from automatically rotating:

Settings > Display > Auto-rotate Screen

This has to be enabled. On my device it was disabled. Nevertheless, the Android docs on getRotation not only fail to point this out but even give you the assumption that getRotation will return the rotation even without a UI. You need a UI. This of course is a problem for something like a service that has no UI but needs to know the orientation of the device for purposes that have nothing to do with user interaction. Personally, I get continuously pissed by Google for hiring amateur programmers who think that accessing hardware features should almost always require some kind of UI. This kind of problem has popped up on many occassions, like having to have a SurfaceView to record a video.

Finally, the getRotation is clearly not required by an app to figure out whether the device is rotated 0, 90, 180 or 270 degrees. With Auto-Rotate Screen turned off, the default camera app is still able to figure out the angular rotation, so it cannot be from getRotation, unless it is somehow capable of turning on the Auto-Rotate Screen setting.

这篇关于getRotation总是返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆