5

I'd like the user to import a bunch of videos/photos into my app. This is the code I was using before:

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.setType("image/*,video/*");
        activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);

The problem I'm having is that the above returns only Photos from the new Google Photos app. If I change the data type to 'video/*' only, the Photos app returns videos. This is for KitKat+

EDIT:

I've tried the following code - it works on some galleries but not with most and not Google Photos:

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    if (AndroidHelper.isKitKatAndAbove()) {
        Log.d(TAG, "Pick from gallery (KitKat+)");
        String[] mimeTypes = {"image/*", "video/*"};
        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
    } else {
        Log.d(TAG, "Pick from gallery (Compatibility)");
        activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
    }
vkislicins
  • 3,331
  • 3
  • 32
  • 62

1 Answers1

1

This is what I ended up doing:

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");
        if (AndroidHelper.isKitKatAndAbove()) {
            Log.d(TAG, "Pick from gallery (KitKat+)");
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
        } else {
            Log.d(TAG, "Pick from gallery (Compatibility)");
            activity.startActivityForResult(intent, REQUEST_CODE_PICK_MEDIA);
        }        

Then when I get results, I check the type of the file. Seems to be working fine.

vkislicins
  • 3,331
  • 3
  • 32
  • 62
  • Yes, but it's kind of an hack, because we only wanted images and videos showing up, this approach allows every type of file. Thanks anyway. – Henrique de Sousa Jan 28 '16 at 13:57
  • 1
    I agree that's a bit of a hack and therefore I didn't post it before :) If you come up with a better solution, please feel free to post an answer - I'm not going to select my own answer as the answer for this one. – vkislicins Jan 29 '16 at 09:47
  • Well, it is the only solution as of now :) Thanks ! – Henrique de Sousa Jan 29 '16 at 13:34
  • Shame on Google. – idish Mar 20 '18 at 00:21
  • 2
    Wrote about this here: https://issuetracker.google.com/issues/123811931 . Please consider starring it. For now, I've alos written a bit nicer way to choose files: https://stackoverflow.com/a/54502555/878126 – android developer Feb 03 '19 at 15:59