无法使用相机后恢复活性

无法使用相机后恢复活性

本文介绍了无法使用相机后恢复活性,应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

谁能帮我检查这个错误,在我的活动我startActivityForResult(用相机拍摄的图像)。拍摄的照片后,我的活动不能恢复。 :(

Who can help me review this bug, In my activity I startActivityForResult (used camera to take image). After taken photo, my activity can't resume. :(

java.lang.RuntimeException: Unable to resume activity {com.example/com.example.view.main.PersonActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=998, result=-1, data=null} to activity {com.example/com.example.view.main.PersonActivity}: java.lang.NullPointerException

--------- Stack trace ---------

    android.app.ActivityThread.performResumeActivity(ActivityThread.java:2458)
    android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
    android.app.ActivityThread.access$600(ActivityThread.java:128)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
    android.os.Handler.dispatchMessage(Handler.java:99)
    android.os.Looper.loop(Looper.java:137)
    android.app.ActivityThread.main(ActivityThread.java:4514)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:511)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    dalvik.system.NativeStart.main(Native Method)
-------------------------------

--------- Cause ---------

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=998, result=-1, data=null} to activity {com.example/com.example.view.main.PersonActivity}: java.lang.NullPointerException

    android.app.ActivityThread.deliverResults(ActivityThread.java:2994)
    android.app.ActivityThread.performResumeActivity(ActivityThread.java:2445)
    android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
    android.app.ActivityThread.access$600(ActivityThread.java:128)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
    android.os.Handler.dispatchMessage(Handler.java:99)
    android.os.Looper.loop(Looper.java:137)
    android.app.ActivityThread.main(ActivityThread.java:4514)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:511)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    dalvik.system.NativeStart.main(Native Method)
-------------------------------

在我的Java的code,在OnActivityResult

In my java-code, at OnActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePath = "";
    switch (requestCode) {
    case MyActivity.RQ_SALE_TAKE_PHOTO:
        {
            if (resultCode == RESULT_OK) {
                if (data != null && data.getExtras() != null && data.getAction() != null) {
                    Bitmap tempBitmap = null;
                    tempBitmap = (Bitmap) data.getExtras().get("data");
                    //.....
                }
            } else {
                //DO SOMETHING HERE
            }
        }
        break;
    }
}

code通话摄像头:

Code call camera :

public static File takePhoto(Activity sender, int requestCode) {
    System.gc();
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    String fileName = Constants.TEMP_IMG + "_" + DateUtils.getCurrentDateTimeWithFormat(null) + ".jpg";
    File retFile = new File(ExternalStorage.getTakenPhotoPath(sender), fileName);
    if (!retFile.exists())
        try {
            retFile.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(retFile));
    sender.startActivityForResult(intent, requestCode);
    return retFile;
}

谁能帮我解释一下上面的错误,以及如何修正这个错误。

Can anyone help me to explain the above error, and how to fix this error.

推荐答案

好像返回意图数据为空

请确保您使用 startActivityForResult 和默认的摄像头应用程序。

Make sure that you use startActivityForResult and the default camera application.

默认的Andr​​oid摄像头应用程序传递回来时,缩略图在返回的意图只返回一个非空的意图。如果传递EXTRA_OUTPUT与写入到一个URL,它会返回一个空的意图和图片是您在传递的URL。

The default Android camera application returns a non-null intent only when passing back a thumbnail in the returned Intent. If you pass EXTRA_OUTPUT with a URL to write to, it will return a null intent and the pictures is in the URL that you passed in.

这篇关于无法使用相机后恢复活性,应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:29