2 clcurie 11 clcurie_11 于 2013.02.20 11:46 提问

设置权限后提示"SDcard mounted RO"

我在 Manifest 文件中添加<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />。当我运行下面的代码时,提示"SDcard mounted RO"。哪里出错呢?

if(!extState.equals(Environment.MEDIA_MOUNTED)) {
        Log.d(Tag.getTag(this),
                ("SDcard not mounted"));
    }
    else if (!extState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        Log.d(Tag.getTag(this),
                ("SDcard mounted RO"));
    }
    else {
        Log.d(Tag.getTag(this),
                ("SDcard mounted RW"));
    }

2个回答

usniyo
usniyo   2013.02.20 12:34
已采纳
!extState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)

不为RO时提示RO。错在这里,去掉“!”

nana4ever
nana4ever   2013.02.27 11:25

你代码的逻辑好像错了

if(!extState.equals(Environment.MEDIA_MOUNTED)) {
    Log.d(Tag.getTag(this),
            ("SDcard not mounted"));
}
else ...

要改为:

if(extState.equals(Environment.MEDIA_MOUNTED)) {
    Log.d(Tag.getTag(this),
            ("SDcard mounted RW"));

}
else if (extState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
    Log.d(Tag.getTag(this),
            ("SDcard mounted RO"));
}
else {
    Log.d(Tag.getTag(this),
            ("SDcard not mounted"));
}
Csdn user default icon
上传中...
上传图片
插入图片