Max
Max

Reputation: 7513

Write permission for external sd card in android 4.0

I am facing a problem while trying to write a files into External SD Card in android 4.0.3,even I have made use of the write permissions like WRITE_EXTERNAL_STORAGE & WRITE_MEDIA_STORAGE, So I have found another way to work on it, but now I want to find out whether my app is possible to write into the Removable SD Card or not, if not then I would like to switch to Internal SD Card.

So now the question is how will I come to know whether writing into Removable SD Card supported or not, So if anyone has done any similar kind of an implementation please feel free to share the code here.

Upvotes: 0

Views: 3592

Answers (3)

Budius
Budius

Reputation: 39856

Answer directly from the API guide:

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

    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: 1

Philip Sheard
Philip Sheard

Reputation: 5825

I have an app that writes to both the internal and external SD cards. I have the WRITE_EXTERNAL_STORAGE permission, but nothing else.

The main problem in dealing with the external SD card is to find the path, because getExternalStorageDirectory() usually returns the internal one. It should be a subdirectory of /mnt, if that helps.

Upvotes: 1

gheese
gheese

Reputation: 1210

To find if you can write to SD card take a look at the Environment class.

String externalStorageState = Environment.getExternalStorageState();

you can then check this state using

Environment.MEDIA_MOUNTED(externalStorageState) and/or Environment.MEDIA_MOUNTED_READ_ONLY(externalStorageState)

Upvotes: 0

Related Questions