Reputation:
I try to download a pdf file from my android phone to Firebase but when I click on the button to select a file in my phone, I get this error: Application not found to perform this action.
Which is quite odd since I have the Adobe Acrobat Reader pdf reader in my phone that allows me to read all the pdf files of my phone.
Please tell me what's wrong with my code.
ps: I execute my code on Android 4.0.3
that is my code.
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_PDF_CODE);
Upvotes: 4
Views: 6541
Reputation: 2326
You may try with this way :
Like :
String[] mimeTypes =
{"application/pdf"};
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType(mimeTypes.length == 1 ? mimeTypes[0] : "*/*");
if (mimeTypes.length > 0) {
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
}
} else {
String mimeTypesStr = "";
for (String mimeType : mimeTypes) {
mimeTypesStr += mimeType + "|";
}
intent.setType(mimeTypesStr.substring(0,mimeTypesStr.length() - 1));
}
startActivityForResult(Intent.createChooser(intent,"ChooseFile"), REQUEST_CODE_DOC);
Upvotes: 0
Reputation: 1802
Try this its working code
Intent intentPDF = new Intent(Intent.ACTION_GET_CONTENT);
intentPDF.setType("application/pdf");
intentPDF.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intentPDF , "Select Picture"), PICK_PDF_CODE);
Upvotes: 3