Camera.Parameters设备特定崩溃(三星S3 Mini)

时间:2013-05-13 09:43:51

标签: java android android-camera samsung-mobile android-camera-intent

以下代码正在开发Galaxy Nexus,三星S3和HTC One X,但它在三星S3 Mini上崩溃

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Log.d(TAG, "entering surfaceChanged");
    Camera.Parameters parameters = camera.getParameters();
    List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();

    // set barcode scene mode
    if (parameters.getSupportedSceneModes() != null && parameters.getSupportedSceneModes().contains(Camera.Parameters.SCENE_MODE_BARCODE)){
        parameters.setSceneMode(Camera.Parameters.SCENE_MODE_BARCODE);
        Log.d(TAG, "setting parameters.setSceneMode(Camera.Parameters.SCENE_MODE_BARCODE)");
    }


    Camera.Size size = previewSizes.get(0);
    if (previewSizes.size() > 2)
        size = previewSizes.get(2);
    else if (previewSizes.size() > 1)
        size = previewSizes.get(1);

    parameters.setPreviewSize(size.width, size.height);
    Log.d(TAG, "picsize w: " + Integer.toString(size.width) + " h: " + Integer.toString(size.height));
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        Log.d(TAG, "setting .setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)");
    } else {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        Log.d(TAG, "setting .setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)");
    }

    // setup cam flash mode
    if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FLASH_MODE_AUTO)){
        parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
        Log.d(TAG, "setting .setFlashMode(Camera.Parameters.FLASH_MODE_AUTO)");
    }

    int maxZoom = parameters.getMaxZoom();
    int zoom = (int) Math.floor(maxZoom / 3);
    if (parameters.isZoomSupported()) {
        if (zoom >= 0 && zoom < maxZoom) {
            parameters.setZoom(zoom);
            Log.d(TAG, "setting .setZoom(" + Integer.toString(zoom) +")");
        } else {
            // zoom parameter is incorrect
            Log.d(TAG, "setting no zoom");
        }
    }
    camera.setParameters(parameters);
    camera.startPreview();
}

日志输出:

8   05-13 10:54:45.864 D/CameraSurfaceView(11784): entering surfaceChanged
9   05-13 10:54:45.874 D/CameraSurfaceView(11784): picsize w: 800 h: 480
10  05-13 10:54:45.874 D/CameraSurfaceView(11784): setting .setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)
11  05-13 10:54:45.874 D/CameraSurfaceView(11784): setting .setFlashMode(Camera.Parameters.FLASH_MODE_AUTO)
12  05-13 10:54:45.874 D/CameraSurfaceView(11784): setting .setZoom(10)
13  05-13 10:54:45.914 D/AndroidRuntime(11784): Shutting down VM
14  05-13 10:54:45.914 W/dalvikvm(11784): threadid=1: thread exiting with uncaught exception (group=0x411422a0)

堆栈跟踪:

java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1452)
at com.getznap.znap.CameraSurfaceView.surfaceChanged(CameraSurfaceView.java:103)
at android.view.SurfaceView.updateWindow(SurfaceView.java:602)
at android.view.SurfaceView.access$000(SurfaceView.java:81)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:173)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1944)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)

我猜测S3 mini有一个我的相机参数有问题。我不拥有S3 Mini,所以我无法逐个测试所有参数。我的代码中是否有明显的错误?

1 个答案:

答案 0 :(得分:12)

发生在

parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
三星不支持这个 你可以尝试

parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);