Permission to write on SD card android

前端 未结 4 681
逝去的感伤
逝去的感伤 2020-12-30 16:49

I have a problem writing to the SD card, here is the code: (Sorry about the layout of the code, just copy pased it )

public class SaveAndReadManager {

 priv         


        
4条回答
  •  不知归路
    2020-12-30 17:17

    Try checking the state of the SD card before you attempt to write to it. It may be used as a shared drive, corrupted, full, etc. A list of states can be found here: http://developer.android.com/reference/android/os/Environment.html

    Here's an example of getting the states:

    String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            mExternalStorageAvailable = mExternalStorageWriteable = true;
        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false;
        } else {
            mExternalStorageAvailable = mExternalStorageWriteable = false;
        }
    

提交回复
热议问题