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 (eg : 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;
}
}
}
Try Replacing
documentIntent.setType("text/*");
with
documentIntent.setType("*/*");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.