0

I am using below code for choose pdf from Storage in Android 10.

Intent intent = new Intent();
        
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), PDF_REQ_CODE);

In startActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);

   if (requestCode == PDF_REQ_CODE && resultCode == RESULT_OK && data != null && data.getData() != null) {
      uri = data.getData();
   }
}

Uri returns like content://com.android.providers.media.documents/document/document:6865 But I want absolute path like storage/..../sample.pdf

Elikill58
  • 4,050
  • 24
  • 23
  • 45
  • 1
    "But I want absolute path like storage/..../sample.pdf" -- that is not an option, sorry. There is no requirement for the user to choose something that is a file on the device, and you will not have access to the file even if they *did* choose a file on the device. Use `ContentResolver` and `openInputStream()` to read in the bytes of the content identified by the `Uri`. – CommonsWare Feb 06 '22 at 16:22
  • `intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); ` Remove that line. You cannot grant anything. Although it has no effect and does not harm you better write not wrong code. – blackapps Feb 06 '22 at 17:12
  • Does [this](https://stackoverflow.com/questions/39696906/select-pdf-file-from-phone-on-button-click-and-display-its-file-name-on-textview) help you? – Abhishek Dutt Feb 06 '22 at 17:51

0 Answers0