尝试使用android.hardware.Camera.setDisplayOrientation时出现RuntimeException

时间:2012-10-01 14:43:30

标签: android android-camera

我在几款设备上测试了我的应用:搭载Android 2.3.5的HTC Wildfire S和搭载Android 4.1的三星Galaxy Nexus。在三星上它可以正常工作,但在HTC上它有时会在显示方向改变时崩溃。它崩溃了例外:

10-01 18:08:40.521: VERBOSE/GeoWash(2111): ScanActivity: onPause
10-01 18:08:40.521: VERBOSE/GeoWash(2111): Camera release
10-01 18:08:41.312: VERBOSE/GeoWash(2111): CameraPreview: surfaceDestroyed
10-01 18:08:41.332: VERBOSE/GeoWash(2111): ScanActivity: onResume
10-01 18:08:41.572: VERBOSE/GeoWash(2111): CameraPreview: acquire
10-01 18:08:41.843: VERBOSE/GeoWash(2111): CameraPreview: surfaceChanged
10-01 18:08:41.863: VERBOSE/GeoWash(2111): onPictureTaken
10-01 18:08:42.023: DEBUG/mm-camera 7x-vfe(74): set vfe_ack_complete true
10-01 18:08:42.023: DEBUG/mm-camera 7x-vfe(74): VFE_START_ACK CAMERA_STATE_PREVIEW_VFE_STARTED
10-01 18:08:42.924: WARN/ActivityManager(136): Binding with unknown activity: HistoryRecord{40a0b4c8 ru.realweb.geowash/.view.ScanActivity}
10-01 18:08:43.084: VERBOSE/GeoWash(2111): CameraPreview: surfaceCreated
10-01 18:08:43.084: VERBOSE/GeoWash(2111): CameraPreview: surfaceChanged
10-01 18:08:43.174: ERROR/AndroidRuntime(2111): FATAL EXCEPTION: main
        java.lang.RuntimeException: set display orientation failed
        at android.hardware.Camera.setDisplayOrientation(Native Method)
        at ru.realweb.geowash.view.CameraView.setPreviewRotation(CameraView.java:647)
        at ru.realweb.geowash.view.CameraView.setupPreview(CameraView.java:570)
        at ru.realweb.geowash.view.CameraView.access$1500(CameraView.java:29)
        at ru.realweb.geowash.view.CameraView$CameraPreview.surfaceChanged(CameraView.java:518)
        at android.view.SurfaceView.updateWindow(SurfaceView.java:557)
        at android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
        at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
        at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
        at android.view.View.draw(View.java:6973)
        at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
        at android.view.ViewGroup.drawChild(ViewGroup.java:1730)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
        at android.view.View.draw(View.java:6973)
        at android.widget.FrameLayout.draw(FrameLayout.java:357)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1997)
        at android.view.ViewRoot.draw(ViewRoot.java:1600)
        at android.view.ViewRoot.performTraversals(ViewRoot.java:1321)
        at android.view.ViewRoot.handleMessage(ViewRoot.java:1957)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:150)
        at android.app.ActivityThread.main(ActivityThread.java:4277)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)

在以下地点:

private void setPreviewRotation( Camera camera ){
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        if(display.getRotation() == Surface.ROTATION_0){
            camera.setDisplayOrientation(90);
        }
    }

有什么建议吗?

0 个答案:

没有答案