Search code examples
androidsamsung-mobilemmscommonsware-cwac

Exception when sharing multiple images in messaging using StreamProvider


I use StreamProvider to serve images to other apps. Everything works fine except in one case: when I try to share multiple images to messaging app on my Samsung S6 device, Android 5.1.1, the messaging app crash with these logs:

Process: com.android.mms, PID: 31790
java.lang.IllegalArgumentException: column 'mime_type' does not exist
  at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
  at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:78)
  at com.android.mms.ui.aif.a(MessageUtils.java:8184)
  at com.android.mms.util.cf.run(HandleComposerAttachment.java:3251)
  at java.lang.Thread.run(Thread.java:818)

Obviously the underlying cursor does not provide a mime_type column. I'm not sure what I have to do to correctly add this column support.

Additional information:

  • I use USE_LEGACY_CURSOR_WRAPPER
  • If use the following code to share images (where imagesUris contains file content uri):

    Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
    shareIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.setType("image/*");
    // Start chooser activity
    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_send)));
    
  • It works on my Genymotion emulator on Android 5.1 (issue only on Samsung version?)

  • It works if I do not use content URI but file path

Solution

  • I'm not sure what I have to do to correctly add this column support.

    You can't, except by rolling your own ContentProvider. I have to adjust LegacyCompatCursorWrapper to handle Samsung's bug. Apps receiving content:// Uri values should not assume the existence of a mime_type column on a query(), largely because there isn't supposed to be one.

    :: sigh ::

    You can track this issue for this enhancement. I hope to have this out by the end of the week.