【问题标题】:Get android device orientation when fixed in portrait mode在纵向模式下固定时获取 android 设备方向
【发布时间】:2015-03-19 13:52:29
【问题描述】:

我们有一个用 xamarin 用 c# 编写的应用程序,所有活动都强制为纵向模式。但是,这会在录制视频时出现一些方向问题。以横向模式录制视频时,元数据错误。我尝试使用这些方法。

Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        Camera.GetCameraInfo(_currentCamera, cameraInfo);

        var surfaceOrientation = WindowManager.DefaultDisplay.Rotation;

但是,无论设备如何转动,它们都会提供固定的角度。即使活动在纵向模式下固定,我如何才能获得实际的设备方向?

【问题讨论】:

    标签: c# xamarin xamarin.android


    【解决方案1】:

    我相信您应该能够根据Resources.Configuration.Orientation 获得方向,其中它将指定Android.Content.Res.Orientation.LandscapeAndroid.Content.Res.Orientation.Portrait 的值

    http://androidapi.xamarin.com/index.aspx?link=T%3AAndroid.Content.Res.Orientation

    http://developer.android.com/reference/android/content/res/Configuration.html#orientation

    否则,如果您无法通过这种方式跟踪 Orientation,您可能需要根据以下 SO 帖子编写 OrientationListener:

    How to detect my screen orientation in portrait locked screen in android?

    【讨论】:

    • 嗨乔恩 很好的答案。然而,配置的使用不起作用,它仍然给出固定的方向。我已经开始实施orientationlistener,所以你的帖子确保我这是正确的方法:)
    猜你喜欢
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多