2

I want to attach a text file of any format in my app. So i have written the following code. The problem is that, i cannot select files from any folder. But if go through any file manager (e.g : ES file explorer), i can access those files. I have also attached screenshot please see that to get clear idea.

Files are greyed out in downloads folder

Files are selectable when opened via file manager

Below is the code i have used.

void pickDocument() {

        Intent documentIntent;

        documentIntent = new Intent(Intent.ACTION_GET_CONTENT);

        documentIntent.setType("text/*");

        startActivityForResult(documentIntent, PICK_DOCUMENTS);
}

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

        try {

            if (resultCode != Activity.RESULT_OK)
                return;

            switch (requestCode) {

                case PICK_DOCUMENTS:

                    Uri documentUri = data.getData();

                    if (mChooseFileDialogListener != null) {

                        mChooseFileDialogListener.onDocumentClick(documentUri, ViewModel.FILE_TYPE);

                    }

                    break;

            }

        } 

}
Harshith
  • 397
  • 1
  • 6
  • 17

1 Answers1

3

Try Replacing

 documentIntent.setType("text/*");

with

documentIntent.setType("*/*");
Haris ali
  • 773
  • 1
  • 13
  • 19
  • 4
    thank you for the response. Now the files are clickable, but images, videos and audio files are also visible. I just want to display documents. So user should be able to select only document files. – Harshith Apr 14 '17 at 06:31
  • did you get any answer file not selectable for specific mime type(not all */*) @Harshith ? – Trupti Nasit Nov 04 '20 at 05:14