在相机android上强制景观

时间:2015-11-06 16:15:20

标签: java android-activity android-manifest phonegap-plugins cordova-plugins

问题

我在将相机强制向横向方向遇到问题。我使用插件“cordova-plugin-camera”

到目前为止我在config.xml中的配置:

<gap:config-file target="AndroidManifest.xml" parent="/manifest/application" mode="merge">
<uses-feature android:name="android.hardware.screen.landscape" />
<activity
    android:name="com.android.camera.Camera"
    android:screenOrientation="landscape"     
    android:configChanges="orientation|keyboardHidden" >
    </activity>
</gap:config-file>

我还将下面的行添加到小部件中。

xmlns:android="http://schemas.android.com/apk/res/android"


我对配置的了解

配置将通过phonegap / cordova与android清单合并。我通过查看以下来源的配置来进行配置:

  
    <config-file target="AndroidManifest.xml" parent="/manifest/application">
    <activity
    android:name="com.google.zxing.client.android.CaptureActivity"
    android:screenOrientation="landscape"
    android:clearTaskOnLaunch="true"
    android:configChanges="orientation|keyboardHidden"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:windowSoftInputMode="stateAlwaysHidden"
    android:exported="false">


可能的解决方案?

所以我搜索了更多,发现了一些强制相机与显示器保持相同方向的Java代码:

 public static void setCameraDisplayOrientation(Activity activity,
     int cameraId, android.hardware.Camera camera) {
 android.hardware.Camera.CameraInfo info =
         new android.hardware.Camera.CameraInfo();
 android.hardware.Camera.getCameraInfo(cameraId, info);
 int rotation = activity.getWindowManager().getDefaultDisplay()
         .getRotation();
 int degrees = 0;
 switch (rotation) {
     case Surface.ROTATION_0: degrees = 0; break;
     case Surface.ROTATION_90: degrees = 90; break;
     case Surface.ROTATION_180: degrees = 180; break;
     case Surface.ROTATION_270: degrees = 270; break;
 }

 int result;
 if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
     result = (info.orientation + degrees) % 360;
     result = (360 - result) % 360;  // compensate the mirror
 } else {  // back-facing
     result = (info.orientation - degrees + 360) % 360;
 }
 camera.setDisplayOrientation(result);
}

来源: http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)

我真的很挣扎如何将此代码附加到我的应用程序。我需要制作一个插件吗?或者是否有另一种方法可以将此代码附加到我的应用程序中?


我想要什么

我希望有人能告诉我配置有什么问题,或者告诉我如何将java代码附加到我的项目中。我对如何强制相机保持景观的其他解决方案持开放态度。 感谢任何帮助。


更多信息

有关gap的更多信息:config-file元素: http://docs.build.phonegap.com/en_US/configuring_config_file_element.md.html

我还创建了一个问题:

0 个答案:

没有答案
相关问题