我正在尝试检查外部存储是否可用,或者我认为我做的都是正确的,但仍然说存储不可用。
private String state;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.externaldata);
eWrite = (TextView) findViewById(R.id.tveWrite);
eRead = (TextView) findViewById(R.id.tveRead);
enviromentState = Environment.getExternalStorageState();
if (enviromentState.equals(Environment.MEDIA_MOUNTED)) {
// read and write
eWrite.setText("you can write");
eRead.setText("you can read");
} else if (enviromentState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
// read but cant write
eWrite.setText("you cannot write ");
eRead.setText("but you can read");
} else {
eWrite.setText("you cannot write");
eRead.setText("you canot read");
}
}
我还给了AndroidManifest.xml
的权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
这是我的虚拟设备的屏幕截图。
答案 0 :(得分:2)
我通过将SD卡大小扩展为 151mb
来解决我的问题