我已将<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"));
}
答案 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"));
}