2009-12-18 94 views
3

我有一个相机预览活动,它被强制保持在横向模式下。获取设备的方向?

有没有一种方法可以告诉手机的当前方向(而不是屏幕方向)。

基本上我想知道用户是否在纵向模式或横向模式下握住手机,所以我可以正确地旋转输出捕捉的位图(现在它只是总是以横向模式输出)。

感谢

+0

你看了这个:http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/? – 2009-12-18 06:21:41

+0

谢谢Nathan,这是一个解决方案。似乎很好地工作(取代了弃用的传感器侦听器类)。虽然这有效,但我希望他们有一个更简单的解决方案,比如context.whatsMyCurrentOrientation()。好吧!谢谢 – Mark 2009-12-18 08:28:16

回答

2
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
     { 
      p.set("orientation", "portrait"); 

      .... 
     } 
     if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) 
     { 
      p.set("orientation", "landscape"); 
      .... 
     }