我已经检查了下面的代码

String state = Environment.getExternalStorageState();
                    if (Environment.MEDIA_MOUNTED.equals(state)) {
                        Log.d("StatusActivity", "sdcard mounted and writable");
                    }
                    else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
                        Log.d("StatusActivity", "sdcard mounted readonly");
                    }
                    else {
                        Log.d("StatusActivity", "sdcard state: " + state);
                    }

输出显示sdcard mounted and writable
但是Environment.getExternalStorageDirectory().canWrite()始终返回false。有人可以建议吗?

最佳答案

您需要对应用程序具有WRITE_EXTERNAL_STORAGE权限。此外,如果要编写仅由应用程序使用的文件,则应将其存储在Context.getExternalFilesDir()中,以防止将应用程序的文件传播到整个公共(public)存储中。如果要编写公共(public)文件,则应将其存储在Environment.getExternalStoragePublicDirectory()中。

关于android - Environment.getExternalStorageDirectory()。canWrite()返回false,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19306485/

10-11 10:27