0

I have a USB-C SSD device connected to my Google Pixel. I can confirm that it is mounted to the device because I can see the removal storage in Settings > Storage, but I'm not sure how to read files from the storage in my app. I know I can use something like FileReader to do it but I don't know what the path is. In Linux, I could find the USB storage in /mnt... but I don't know what Android / Google Pixel does

Carpetfizz
  • 8,707
  • 22
  • 85
  • 146

1 Answers1

0

You probably can find a path using getExternalFilesDirs(). The last entry will be your private directory on the pendrive.

Further you can use Intent.ACTION_OPEN_DOCUMENT_TREE and Intent.ACTION_OPEN_DOCUMENT to let the user choose the drive or a file on the drive.

greenapps
  • 11,154
  • 2
  • 16
  • 19
  • 1
    Thanks for the reply, the first one gave me `[/storage/emulated/0/Android/data/com.company.my.app/files]` For the second one, I did `startActivityForResult` on `Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);` and got the URI from the returning intent, which looks like `/tree/04F8-111C:` , I tried doing `File f = new File(uri.getPath)` and `f.listFiles()` but that returns `null` – Carpetfizz May 25 '17 at 16:14
  • No the uri does not look like that. You used uri.getPath() but the content scheme is uri.toString(). And one cannot use the File class for a content scheme. – greenapps May 25 '17 at 18:00
  • Strange: why didnt you tell the value for the second or third path delivered by getExternalFilesDirs()? With them you can use the File class. – greenapps May 25 '17 at 18:02
  • [this](https://stackoverflow.com/questions/44185477/intent-action-open-document-tree-doesnt-seem-to-return-a-real-path-to-drive/44185706?noredirect=1#comment75386501_44185706) answer actually helped me solve the question – Carpetfizz May 25 '17 at 18:03