5

我正在尝试检查外部存储是否可用,甚至我认为我所做的一切都是正确的,但它仍然说存储不可用。

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

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

截屏

4

1 回答 1

2

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

于 2013-01-23T18:42:14.560 回答