问题描述
- 设置权限后提示"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")); }
解决方案
!extState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)
不为RO时提示RO。错在这里,去掉“!”
解决方案二:
你代码的逻辑好像错了
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"));
}
时间: 2024-12-01 06:46:56