简体   繁体   English

Android 相机意图不返回/锁定

[英]Android Camera intent doesn't return/locks up

I'm trying to take a picture from the Camera using intent with onActivityResult but every time I take a picture the camera locks up and never returns.我正在尝试使用带有onActivityResult的意图从相机拍照,但每次我拍照时相机都会锁定并且永远不会返回。 Any reason why this might happen?为什么会发生这种情况? This is the code I'm using:这是我正在使用的代码:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.v(TAG,"Camera callback: "+Integer.toString(resultCode));
    if (requestCode == CAMERA_PIC_REQUEST) {
        try{
            Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
            Log.v("Picture view",data.getData().toString());
            ImageView image = new ImageView(this);
            image.setImageBitmap(thumbnail);  
            setContentView(image);
        }
        catch(Exception e){
            Log.e(TAG, "something happened");
            e.printStackTrace();
        }

    }
}

This is the LogCat output after taking a picture:这是拍完照片后的LogCat output:

06-12 19:46:03.881: VERBOSE/camera(443): Start autofocus.
06-12 19:46:04.521: VERBOSE/camera(443): doSnap: mFocusState=1
06-12 19:46:04.721: VERBOSE/camera(443): mAutoFocusTime = 790ms

Then it just locks up and onActivityResult never fires.然后它只是锁定并且onActivityResult永远不会触发。

Thanks for your inputs.感谢您的投入。

I read a bunch of tutorials and everyone does it different.我读了一堆教程,每个人的做法都不一样。 The official Android Docs use the Camera -class (step by step tutorial on the linked page).官方 Android 文档使用Camera -class(链接页面上的分步教程)。

I found this other tutorial (which uses the MediaStore -class, like you), but put an extra for the Output-File on the Intent.我找到了另一个教程(它使用MediaStore -class,就像你一样),但是在 Intent 上为 Output-File 添加了一个额外的内容。

You might want to check both of this tutorials and see if one works for you.您可能想查看这两个教程,看看是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM