Skip to content Skip to sidebar Skip to footer

How To Access External Micro Sd Card Of The Phone?

Does anyone know how can I get SD card of the phone? I know that someone will tell me its getExternalStorageDirectory() or Environment.getExternalStoragePublicDirectory(). But un

Solution 1:

Check out the answer by CommonsWare on the same topic https://stackoverflow.com/a/5695129/582571

He mention that we can not distinguish between mobile's inbuilt external storage and removable external storage.

But by Aleadam answer https://stackoverflow.com/a/6049446/582571 we can only check that is the External Storage is removable or not with isExternalStorageRemovable() function.

I hope you will get idea.

Solution 2:

You can below condition to check whether SDCard is available or not

if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {

     //Check for the file
     File appFolder = new File(Environment.getExternalStorageDirectory() + File.separator
                + context.getString(R.string.app_name));

     boolean exist = appFolder.exists();
}

Solution 3:

I was facing the same problem. I didn't know how to access external sd card location. I was developing an app wherein I had to access the external sd card to read and write some stuff. I tried different methods including the pre-defined android libraries. These are the methods I used:-

These were the misses:-

Filepath= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
FilemyFile=newFile(path, "test.txt"); 

Fileroot= Environment.getExternalStorageDirectory();
Filedir=newFile(root.getAbsolutePath()+"/Download");

Filef= getExternalFilesDir(null); 
Filefile=newFile(f,"test.txt");

These all were accessing internal storage "/storage/sdcard0" or "/storage/emulated/0". The reason being in the android device the portion of the internal storage acts as an external storage. So in case you have internal storage of around 16 Gb or more and there is an option to expand the device with sd card, then this is the only way i guess to access the external sd card because even the built-in functions and libraries of the android studio will access internal storage as external storage.

Finally I used this:-

StringextFilePath="/storage/sdcard1/Download";
FilemyFile=newFile(extFilePath, "test.txt");

and it worked. So you see where pre-defined android libraries/functions fail, I was able to do the task with the simple String.

Apart from this if you want to check the path for external storage your device, try this:-

String sdpath,sd1path,usbdiskpath,sd0path;

if(newFile("/storage/extSdCard/").exists())
{sdpath="/storage/extSdCard/";
Log.i("Sd Cardext Path", sdpath);}

if(newFile("/storage/sdcard1/").exists())
{sd1path="/storage/sdcard1/";
Log.i("Sd Card1 Path",sd1path);}

if(newFile("/storage/usbcard1/").exists())
{usbdiskpath="/storage/usbcard1/";
Log.i("USB Path",usbdiskpath);}

if(newFile("/storage/sdcard0/").exists())
{sd0path="/storage/sdcard0/";
Log.i("Sd Card0 Path",sd0path);}

Checking these might help you know what path to choose while accessing external sd card. I hope this helps others.

Solution 4:

Removable storage path is diff in device to device. The example of Removable path are: 1. mnt/ext 2. mnt/externalsd 3. mnt/external_sd

My device use mnt/external_sd.

you can check the path of your file from vold.fstab file. this file is under systems folder. The path of file is:

"/etc/vold.fstab"

Solution 5:

I was facing the same problem with my latest device. Then I found that removable SD card can be accessed at /mnt/ext_sdcard/. and it worked for me. I was able to list all the files stored in removable external sd card at this location.

Following is the code: new File("/mnt/ext_sdcard/").listFiles();

Post a Comment for "How To Access External Micro Sd Card Of The Phone?"