Search code examples
androidcameraeditorphotos

Android new Photos app crashes when trying to edit a picture after using the camera


I was using this code to take a picture and the editing it, but now, the new Photos app crashes.

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);
        }
    }
}

Error is

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)

Anyone having any issue after installing the new Photos app?

BTW, I'm also getting this error as soon as the Camera opens

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)

Solution

  • Ok, so after thinking about which string could be null I found that when you call

    intent.setData(uri);
    

    the call makes type=null;

    Looks like this wasn't a problem on the previous Photo app, but now you need to call

    intent.setDataAndType(uri, type);
    

    and that should fix the problem.

    One side note:

    When you set the OUTPUT to the Editor, you have to use a file Uri and not a content Uri (I don't remember this being a problem until now) and also sending the file Uri for the same camera picture didn't work for me, so I just removed the call to

    intent.putExtra(MediaStore.EXTRA_OUTPUT, ...);
    

    and everything works fine now