Toux
Toux

Reputation: 100

Best way to know sd card Path Android

I need to know in the most of the devices the sd card path. I have some problems for that I actually use:

 Environment.getExternalStorageDirectory();

But some phones don't return correct path... I don't know why.

Which is the best way to check Sd Card Path for different devices and OS versions?

Upvotes: 0

Views: 719

Answers (3)

Jared Rummler
Jared Rummler

Reputation: 38121

This is always the best approach:

Environment.getExternalStorageDirectory();

You could also get the environmental variable which is on all Android devices like this:

String sdcardPath = System.getenv("EXTERNAL_STORAGE");

Upvotes: 0

lalith
lalith

Reputation: 55

I think this is best one ...

 Cursor cursor = getContentResolver().query(_uri, new String[] { ndroid.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                      cursor.moveToFirst();

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006664

There is no "sd card path" in Android.

At the present time, Android has internal storage and external storage, and that is it. Environment.getExternalStorageDirectory(); returns the root of external storage. Whether external storage is:

  • on the same partition of the on-board flash as is used for internal storage, or
  • on a separate partition of the on-board flash, or
  • is some removable drive, like a microSD card, or
  • is something else entirely

is up to the device manufacturer.

Similarly, if the device manufacturer offers additional data stores (e.g., a removable card in addition to external storage as part of on-board flash), right now, those additional data stores are for the exclusive use of the device manufacturer. That manufacturer may elect to document how you can use them, or the manufacturer may integrate those data stores with something else that you can access (e.g., have multimedia files by indexed and accessible via MediaStore).

You can read more about this in the documentation on external storage.

So, by definition, Environment.getExternalStorageDirectory(); is "the correct path" representing external storage.

Upvotes: 3

Related Questions