Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Open External Storage directory(sdcard) for storing file

I want to open external storage directory path for saving file programatically.I tried but not getting sdcard path. How can i do this?is there any solution for this??

private File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + ""); 

or

private File path = new File(Environment.getExternalStorageDirectory() + ""); 

I tried getting path from above both methods but both are pointing internal memory.

When we open storage memory if sdcard is peresent it will shows like below- enter image description here

device storage & sd memory card.

I want to get sd memory path through coding. I have given permissions in manifest-

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />     <uses-permission android:name="android.permission.STORAGE" />     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
like image 927
yuva ツ Avatar asked Mar 06 '14 08:03

yuva ツ


People also ask

What is the file path for SD card in Android?

The external storage was often a “Secure Digital” (or SD) card. On devices without a physical SD Card, it is often emulated. Traditionally the SD Card is referenced via the file path “/sdcard” for consistency.

How do I open storage folder on Android?

Head to Settings > Storage > Other and you'll have a full list of all the files and folders on your internal storage. (If you'd prefer this file manager be more easily accessible, the Marshmallow File Manager app will add it as an icon to your home screen.)


1 Answers

I had been having the exact same problem!

To get the internal SD card you can use

String extStore = System.getenv("EXTERNAL_STORAGE"); File f_exts = new File(extStore); 

To get the external SD card you can use

String secStore = System.getenv("SECONDARY_STORAGE"); File f_secs = new File(secStore); 

On running the code

 extStore = "/storage/emulated/legacy"  secStore = "/storage/extSdCarcd" 

works perfectly!

like image 84
Rijul Gupta Avatar answered Sep 20 '22 19:09

Rijul Gupta