Android 清单权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Java 文件(第一次尝试)
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/newAppFolder";
File dir = new File(path);
dir.mkdirs();
Java文件(第二次尝试)
String state = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(state)) {
File dir = new File(Environment.getExternalStorageDirectory(), "newAppFolder");
if(!dir.exists()) {
dir.mkdirs();
Toast.makeText(getApplicationContext(), "Folder Created", Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getApplicationContext(), "Folder exists", Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getApplicationContext(), "SD Card Not Found", Toast.LENGTH_LONG).show();
不幸的是,这两种尝试都没有创建我需要的 newAppFolder 文件。有人可以告诉我我做错了什么吗?
注意:在第二次尝试中,应用程序 toast 一直显示文件夹已创建