本文介绍了takepicture挂在Android 2.3.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些$ C $的拍照中的Andr​​oid 2.1和2.2这工程CS。但是,打破了C $ CS这些$在的Andr​​oid 2.3。花时间来解决这个问题,其中又以徒劳之后,我想问一下在这里帮助。

I have some codes of taking picture which works in Android 2.1 and 2.2.But these codes broke at Android 2.3.After spending time to fix this issue which went in vain, I would like to ask for help here.

我的code流向拍照是这样的:

My code flow to take picture is like this:

创建一个类Camlayer扩展了SurfaceView

public class CamLayer extends SurfaceView implements SurfaceHolder.Callback {
    private void init(Context context){
        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mCamera = Camera.open();
    }

    public CamLayer(Context context) {
        super(context);
        init(context);
    }

    public CamLayer(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Log.i(TAG+".surfaceChanged", "being called!");
        Log.i(TAG+".surfaceChanged", "w="+w);
        Log.i(TAG+".surfaceChanged", "h="+h);
        if (isPreviewRunning) {
            mCamera.stopPreview();
        }

        try {
            mCamera.setPreviewDisplay(holder);
            mCamera.setPreviewCallback(mPreviewCallback);
        } catch (IOException e) {
            Log.e(TAG+".surfaceCreated", "mCamera.setPreviewDisplay(holder);");
        }

        Camera.Parameters p = mCamera.getParameters();
        setOptimalSize(p, w, h, SIZEOFPREVIEW);
        setOptimalSize(p, w, h, SIZEOFPICTURE);
        mCamera.setParameters(p);

        mCamera.startPreview();
        isPreviewRunning = true;
    }

    public void takePicture(){
        Log.i(TAG+".takePicture", "being called!");
        mCamera.takePicture(null, null, mPictureCallback);
        Log.i(TAG+".takePicture", "call ended!");
    }
}

CamLayer.takePicture()将被外部类调用启动。

CamLayer.takePicture() will be called by external classes to start.

现在的问题是,在安卓2.3.3的 takePicture 将挂起,这样的ANR的问题被发现。在 /data/anr/traces.txt ,下面被发现。正如你所看到的, native_takePicture 永不再来。

The problem is that at Android 2.3.3, the takePicture will hang, so an ANR problem is found. In /data/anr/traces.txt, below are found. As you can see, the native_takePicture never returns.

DALVIK主题:

(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE

  | group="main" sCount=1 dsCount=0 obj=0x40022170 self=0xce68

  | sysTid=2411 nice=0 sched=0/0 cgrp=default handle=-1345006464

  at android.hardware.Camera.native_takePicture(Native Method)

  at android.hardware.Camera.takePicture(Camera.java:746)

  at android.hardware.Camera.takePicture(Camera.java:710)

  at oms.cj.tube.camera.CamLayer.takePicture(CamLayer.java:256)

  at oms.cj.tube.camera.DefineColor.takePicture(DefineColor.java:61)

  at oms.cj.tube.camera.DefineColor.onKeyUp(DefineColor.java:71)

  at android.view.KeyEvent.dispatch(KeyEvent.java:1280)

  at android.app.Activity.dispatchKeyEvent(Activity.java:2078)

  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:16
66)
  at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2571)

  at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2546)

  at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)

  at android.os.Handler.dispatchMessage(Handler.java:99)

  at android.os.Looper.loop(Looper.java:123)

  at android.app.ActivityThread.main(ActivityThread.java:3691)

  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:841)

  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)

  at dalvik.system.NativeStart.main(Native Method)

有没有人有同样的问题?并知道如何解决它?

Is there anybody having the same problem? And know how to fix it?

推荐答案

我还观察到mCamera.takePicture(NULL,NULL,处理程序)的冻结。我试图清除preVIEW处理程序:调用takePicture()之前mCamera.set previewCallback(空),和它的作品现在

I also observed mCamera.takePicture(null, null, handler) to freeze. I tried to clear the preview handler: mCamera.setPreviewCallback(null) before calling takePicture(), and it works now.

这篇关于takepicture挂在Android 2.3.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 09:04