0

So I'm making an app that requests a file from the phone's storage (external storage - not external SD Card, the internal one). But the path is awkward when I select the file from Downloads: /document/[number here, for example, 4].

Does anyone know how to get the real path of that file? Because it exists on the Download folder, but I wanted it to when it's selected, I get the real path of it and not that weird path which actually doesn't even exist. This happens at least on Nougat (Android Studio emulator) and on KitKat (both the emulator and my phone). Any help is appreciated.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Edw590
  • 447
  • 1
  • 6
  • 23
  • 1
    Because in Nougat and above devices, It return document uri path instead of file path. – Abhay Koradiya Apr 15 '19 at 04:46
  • 1
    you can check [here](http://technophilegeek.blogspot.com/2018/11/android-get-file-path-from-uri-real.html). – Abhay Koradiya Apr 15 '19 at 04:49
  • 1
    You are getting the URI. If you want to get the real path, check out this answer: https://stackoverflow.com/a/17546561/7090731 – Nandan Desai Apr 15 '19 at 05:14
  • Thank you both! It was really that. I didn't know. It was just shown as /document/number. The solution that worked was @AbhayKoradiya 's. Others I tried would return a NullPointerException but that one is very complete. Could you put that as a solution? Btw, that appears too in KitKat. – Edw590 Apr 15 '19 at 18:52

1 Answers1

0

As pointed by Abhay Koradiya and Nandan Desai, the path was an Uri path, so I used this code to solve the problem and convert to normal path, given by Abhay Koradiya: http://technophilegeek.blogspot.com/2018/11/android-get-file-path-from-uri-real.html. Again, thank you both for the help!

Edw590
  • 447
  • 1
  • 6
  • 23