Muhamed Riyas M
Muhamed Riyas M

Reputation: 5183

External Storage issue in android

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)?

Upvotes: 1

Views: 176

Answers (2)

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

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;
}

Upvotes: 2

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

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

Upvotes: 3

Related Questions