I want to pick a file (other than image, video or audio), like pdf, ppt, docx, txt etc.,,

Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select File"),Constant.SELECT_FILE);

Above method is not working.

When I do the action Dialog box appears With message "No Application can perform this action"

有帮助吗?

解决方案

Because there is no any application installed on device which is handle your intent with action Intent.ACTION_GET_CONTENT. So if your device running on Android 4.4 then try with Intent.ACTION_OPEN_DOCUMENT or Implement your own File Browser Activity.

Look at https://github.com/vaal12/AndroidFileBrowser and aFileChooser

其他提示

Try this:

The problem is that there is no app installed to handle opening the PDF. You should use the Intent Chooser, like so:

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ filename);
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(file),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

Intent intent = Intent.createChooser(target, "Open File");
try {
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    // Instruct the user to install a PDF reader here, or something
}   
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top