Reputation: 397
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.
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;
}
}
}
Upvotes: 2
Views: 2289
Reputation: 783
Try Replacing
documentIntent.setType("text/*");
with
documentIntent.setType("*/*");
Upvotes: 3