0

In my android application i need a file picker that only pick images and document.I have implemented that but it will pick other files like videos.I only need to pick documents like pdf,excel,txt,etc.. and images and all those under a file size of 5mb.Below is the code that i currently using.

final String[] ACCEPT_MIME_TYPES = {"application/*", "image/*", "text/*" };
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_MIME_TYPES, ACCEPT_MIME_TYPES);
    //intent.setType("file/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"),FILE_SELECT_CODE);
    } catch (Exception ex) {
        System.out.println("browseClick :"+ex);//android.content.ActivityNotFoundException ex
    }

I don't what i was doing wrong here that makes the selector to pick videos and othere files.Please help me to solve this.

KJEjava48
  • 1,967
  • 7
  • 40
  • 69

1 Answers1

0

That is not literally possible. You are welcome to use a MIME type of text/plain instead of /, but:

  • There is no guarantee that this will only return files with a .txt
    extension.
  • There is no guarantee that there is any app on the device that can handle ACTION_GET_CONTENT of that MIME type.
  • There is no
    guarantee that any "file manager" will honor your MIME type; they may elect to display all files anyway.
Ruthwik
  • 539
  • 1
  • 4
  • 5