Best way to know sd card Path Android

后端 未结 3 334
灰色年华
灰色年华 2021-01-28 03:25

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();


        
相关标签:
3条回答
  • 2021-01-28 04:17

    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");
    
    0 讨论(0)
  • 2021-01-28 04:22

    I think this is best one ...

     Cursor cursor = getContentResolver().query(_uri, new String[] { ndroid.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
                          cursor.moveToFirst();
    
    0 讨论(0)
  • 2021-01-28 04:27

    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.

    0 讨论(0)
提交回复
热议问题