Naitik
Naitik

Reputation: 816

How to get path of directory which is in SD Card?

I want to create directory in SD card same as in the internal storage.

My internal storage path is "sdcard/<my_directory_name>/"

I want to create the same directory in root of SD card.

I have try the following ways to find the path of directory.

  1. sdcard1/<my_directory_name>/
  2. Environment.getExternalStorageDirectory() +"/<my_directory_name>/"

Please suggest the way to find SD card path.

Upvotes: 0

Views: 1808

Answers (2)

Bugs Buggy
Bugs Buggy

Reputation: 1546

Although as CommonsWare answered, you cannot read or write in Secondary External Storage, here's a way to generate it's path.

System.getenv("SECONDARY_STORAGE"); //returns /storage/extSdCard

You can also use String path = "/storage/extSdCard"; but again you cannot write files there.

Edit: As @CommonsWare commented, there is no guarantee of this method. Though when I tested it, it worked, but again, if he says there's no guarantee, you can take his word.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006724

You do not have arbitrary access to removable storage on Android 4.4+. Hence, there is no useful path, from a filesystem standpoint. You are welcome to use getExternalFilesDirs() and kin -- if they return 2+ locations, the second and subsequent ones are on removable storage, and you can read and write to those locations.

Upvotes: 2

Related Questions