문제

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