Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting both Photos and Videos from the new Google Photos app on Android

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);
    }
like image 628
vkislicins Avatar asked Nov 09 '22 12:11

vkislicins


1 Answers

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.

like image 183
vkislicins Avatar answered Nov 15 '22 13:11

vkislicins