EnJ
EnJ

Reputation: 197

Access files stored in the shared storage on Android

I copy a file from USB to my SamSung S7 tablet using My Files app shipped with my tablet. I can find this file under /data using My Files app. I believe this file is stored in the shared external storage. As pointed in https://developer.android.com/training/data-storage

I need Android Storage Access Framework to access this file.

I want to access this file with my own app and I need to know the URL. What's the URL look like?

Thanks.

YL

Upvotes: 1

Views: 415

Answers (1)

minchaej
minchaej

Reputation: 1814

A file URL looks like this in Android and you can use this type of URL to access files:

file:///path/to/foo.txt

  • file:// is used to refer to URL pointing to a world-readable file.
  • You can get path to directory from one of these getExternalFilesDir() or getExternalCacheDir() or getExternalMediaDirs(). Hence, getExternalStorageDirectory is deprecated and no longer recommended for use. (Read more here)
  • Lastly, make sure you have made permission to access: WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE

Let me know if you have any questions. Thanks.

Upvotes: 1

Related Questions