1

I'm trying to display only gallery and File manager in the chooser intent

So, i tried something like below

Intent intent = new Intent();
                intent.setType("image/*");
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                intent.setAction(Intent.ACTION_PICK);
                startActivityForResult(Intent.createChooser(intent, "Select Picture"), RESULT_LOAD_IMAGE);

But along with gallery and File Explorer it is showing other apps too. It is also showing google drive

So, i decided to choose only first two intents and remove others.

How to achieve this ?

shiv
  • 165
  • 11

2 Answers2

2

use this type of code :

Intent i= new Intent(Intent.ACTION_GET_CONTENT);
    i.setType("image/*");

    Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    pickIntent.setType("image/*");

    Intent chooserIntent = Intent.createChooser(i, "Select Image");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

    startActivityForResult(chooserIntent, PICK_IMAGE);
1

For your case the easiest way to achieve what you need is

to add below line

intent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

By adding above line you can get rid of installed apps by user. but be aware of one thing

  • when you use intent.setAction(Intent.ACTION_PICK); you will see Gallery, File Manager, and Any Inbuilt photo app provider by manufacturer of phone.
  • when you use intent.setAction(Intent.ACTION_GET_CONTENT); along with above you will also see Google drive.

Don't go for first two chooser intents it is not recommended and I don't know the reason, Also I don't know how to do that.

Hope, This gives a proper explanation with answer.

Vikas Acharya
  • 3,550
  • 4
  • 19
  • 52