android – Environment.getExternalStorageState()在虚拟设备上返回false

我正在尝试检查外部存储是否可用,或者我认为我做得正确它仍然说存储不可用.

    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"/>

这里是我的虚拟设备的屏幕截图.

最佳答案 我通过将SD卡大小扩展到151mb来解决我的问题

点赞