1

I am using the path as "/mnt/sdcard/myfolder/myfile" to store my file in android app. Will it give any error when the app running on the phone which does not have any sdcard slot(phone like Nexus S)?

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Muhamed Riyas M
  • 5,055
  • 3
  • 30
  • 31
  • check this link : http://stackoverflow.com/a/15744282/1381827 – Dhaval Parmar Apr 03 '13 at 05:45
  • Use the location from /sdcard/myfolder/myfile, /mnt is not necessary. To check the availability of sdcard you can use, android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); – Jibran Khan Apr 03 '13 at 05:45
  • 1
    Also note that you shouldn't use a hardcoded path to access external storage. If you are not already, you should be using Environment.getExternalStorageDirectory(). – Brett Duncavage Apr 03 '13 at 05:56

2 Answers2

3

You have to check whether external storage is available or not

private static boolean isExternalStorageAvailable() {
    String extStorageState = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
        return true;
    }
    return false;
}

Demo

Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
2

Please check this link :

boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
} else {
    // Something else is wrong. It may be one of many other states, but all we need
    //  to know is we can neither read nor write
    mExternalStorageAvailable = mExternalStorageWriteable = false;
}
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177