As I am able to open the Downloads folder but PDF looks like disabled so I am not able to select PDF files. Is there any other way to achieve this ?
Here is the code for Button Click
case R.id.pdf_Upload:
Intent intent = new Intent();
intent.setType("pdf/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), REQUESTCODE_PICK_Pdf);
break;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUESTCODE_PICK_Pdf:
if (requestCode == REQUESTCODE_PICK_Pdf && resultCode == RESULT_OK
&& null != data) {
Uri selectedPdf = data.getData();
PdfSelected.setVisibility(View.VISIBLE);
if (selectedPdf.getLastPathSegment().endsWith("pdf")) {
System.out.println("Uri of selected pdf---->" + selectedPdf.toString());
} else if (resultCode == RESULT_CANCELED){
Toast.makeText(this, "Invalid file type", Toast.LENGTH_SHORT).show();
}
}
}
Permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
this cod work for me
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, SAVE_REQUEST_CODE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With