在使用相机后尝试编辑图片时,Android新照片应用会崩溃

时间:2015-06-05 18:29:29

标签: android camera editor photos

我使用此代码拍摄照片并对其进行编辑,但现在,新的照片应用程序崩溃了。

private Uri cameraImagePath;
private void takePhoto() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    ContentValues values = new ContentValues(2);
    values.put(MediaStore.Images.Media.MIME_TYPE, IMAGE_MIME_TYPE);
    values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());

    cameraImagePath = getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraImagePath);
    startActivityForResult(takePictureIntent, TAKE_PHOTO_FROM_GALLERY);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PHOTO_FROM_GALLERY && resultCode == Activity.RESULT_OK) {
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("image/*");
        intent.setData(cameraImagePath);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraImagePath);

        List<ResolveInfo> list = getApp().getPackageManager().queryIntentActivities(intent, 0);
        int size = list.size();
        if (size == 0) {
            cropPicture(selectedImage);
        } else {
            startActivityForResult(intent, EDIT_IMAGE);
        }
    }
}

错误是

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.google.android.apps.photos, PID: 11521
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference
            at dzn.b(PG:57)
            at com.google.android.apps.photos.photoeditor.intents.EditActivity.a(PG:6245)
            at kcf.a(PG:313)
            at kcs.run(PG:1302)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

安装新照片应用后有任何问题吗?

顺便说一下,相机打开后我也会收到此错误

cannot compute fingerprint for: content://media/external/images/media/168992
    java.io.FileNotFoundException: No such file or directory
            at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
            at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:691)
            at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1080)
            at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
            at android.content.ContentResolver.openInputStream(ContentResolver.java:646)
            at ika.a(PG:160)
            at iil.a(PG:136)
            at com.google.android.libraries.social.autobackup.FingerprintScannerIntentService.onHandleIntent(PG:77)
            at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.os.HandlerThread.run(HandlerThread.java:61)

1 个答案:

答案 0 :(得分:5)

好的,所以在考虑哪个字符串可以为null后,我发现当你调用

intent.setData(uri);

调用使type = null;

在上一张Photo应用中看起来这不是问题,但现在你需要致电

intent.setDataAndType(uri, type);

这应该解决问题。

一面注意:

当您将OUTPUT设置为编辑器时,您必须使用文件Uri而不是内容Uri(我不记得这是一个问题,直到现在)并且还发送文件Uri用于相同的相机图片没有为我工作,所以我刚刚删除了对

的电话
intent.putExtra(MediaStore.EXTRA_OUTPUT, ...);

现在一切正常