Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get removable sd card path in android

How can i get extSdcard path in android?

There are 2 storage, first external storage in which all the phones have it but there is second storage which is called removable storage (micro sdcard).

I want to get the path to the micro sdcard in android, how is that possible?

like image 910
Ali Akhgar Avatar asked Apr 15 '26 06:04

Ali Akhgar


2 Answers

Starting from KitKat, you have access to a method to get that directory :

Context.getExternalFilesDirs()

Note that it may return null if the SD card is not mounted or moved during the access. Also, you might need to add these permissions to your manifest file :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Apparently some users had trouble with this method, not returning the SD card path. I found some useful informations on how it can works and how it can not depending on the device on this post.

like image 165
YumeYume Avatar answered Apr 17 '26 18:04

YumeYume


Check this https://developer.android.com/guide/topics/data/data-storage.html#filesExternal for complete reference as you need to define permission to read and write to the external SD also there is code in the above link which checks if SD card is available before performing any action

like image 39
mdb Avatar answered Apr 17 '26 18:04

mdb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!