0

How to catch which app user picked to select media programmatically? Google Photo or Gallery

1 Answers1

0

See this code to select images or videos from the Gallery or Google Photos

 int PICK_IMAGE_REQUEST = 111;


imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v)

                String[] mimeTypes = {"video/*","image/*"};

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.setType(mimeTypes.length == 1 ? mimeTypes[0] : "*/*");
        if (mimeTypes.length > 0) {
            intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
        }
    } else {
        String mimeTypesStr = "";
        for (String mimeType : mimeTypes) {
            mimeTypesStr += mimeType + "|";
        }
        intent.setType(mimeTypesStr.substring(0,mimeTypesStr.length() - 1));
    }
    startActivityForResult(Intent.createChooser(intent,"ChooseFile"), PICK_IMAGE_REQUEST);


        }
    });
  • As far as i know, there is no such a way to know about application name which is selected by the user,and you do not need to worry about it.If you tell me your actual problem i will help it out :) – Akshay Dobariya Mar 06 '19 at 08:22
  • okay) My problem is when I want to pick a media, device suggesting Gallery and Google Photos. Imagine if user picked Google photos. Then app shows me only image or video(I want both). Google photo accept only first mimetype – Miras Temirbay Mar 06 '19 at 08:27
  • you can set your own mimetype, and set that mimetypes to the intent using EXTRA_MIME_TYPES. it will only allow particular types(in your case Photos/Video). whether it is Gallery or Google Photos, it will work in both. – Akshay Dobariya Mar 06 '19 at 08:35