设置权限后,SD卡仅RO

时间:2012-02-24 06:21:43

标签: android

我已将<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />添加到Manifest,但在执行以下代码时仍然会获得“SDcard挂载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"));
    }

1 个答案:

答案 0 :(得分:0)

您的代码逻辑似乎有误?

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

“不等于MEDIA_MOUNTED”可能是“mounted_ro”或“未装载”......

无论如何,你应该改为......

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