我在 onCreate() 方法的第一个 Activity 上创建应用程序文件夹,但文件夹没有创建。这是代码
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
File fil = new File(this.getFilesDir().getPath()+File.separator+"MyContactsBackUp");
fil.mkdirs();
} else {
File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"MyContactsBackUp");
directory.mkdirs();
}
最佳答案
试试这段代码
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
File podcastFolder = new File(Environment.getExternalStorageDirectory() + File.separator
+ getString(R.string.app_name));
} else {
/* save the folder in internal memory of phone */
File podcastFolder = new File("/data/data/" + getPackageName()
+ File.separator + getString(R.string.app_name));
}
关于android - 如何在android中创建应用程序文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402702/