how to check internal and external storage if exist

后端 未结 5 620
说谎
说谎 2020-11-29 04:03

How do i know if there are internal and external storage in android pragmatically? does anyone how to know how to check both internal and external storage

thanks in

5条回答
  •  被撕碎了的回忆
    2020-11-29 04:44

    it's already explained in android documentation.

    Code taken from documentation

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

提交回复
热议问题