0

I am selecting a PDF file below

press here

I am selecting the sample.pdf

This is the path I am getting (the one in textview)

But I think the the path should be this one(Location)

the code that I used was using intent uri and string as seen below

 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("application/pdf");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_CODE);
    Log.e("startSearch: ","worked");// this code ends here

//new function(i.e onActivityResult()) starts here

if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            final Uri uri = data.getData();
            Log.e("on activity result"," yes");

            //File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + File.separator + uri.getPath() +".pdf");
            final File file = new File(uri.getPath().toString());
            path.setText(file.getPath());
    }
}

what should I do to get the right path of the PDF?

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
so low
  • 1
  • 7
  • uri.toString() is the right content scheme of your file. Dont try to get something else. You will not need the File class at all. You did not tell for what you need a 'path'. Please dont post so many links. Just tell what is going on. – blackapps Dec 13 '19 at 13:26
  • i think , the thing tat i want is cleared out in the 3rd and 4th link – so low Dec 13 '19 at 13:40

0 Answers0