[英]Files are not selectable on Intent.ACTION_GET_CONTENT
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.
但是,如果通过任何文件管理器(例如:ES文件浏览器),我都可以访问这些文件。 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("*/*");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.