问题描述
我使用以下代码在Android单元的SDCARD上创建一个文件夹" mymir"和一个文件" .nomedia"(在mymir-folder中).但是,以某种方式失败了,除了将" .nomedia" -file放置在不存在的文件夹中.这是代码:
private String EnsureRootDir() throws IOException { File sdcard = Environment.getExternalStorageDirectory(); File mymirFolder = new File(sdcard.getAbsolutePath() + "/mymir/"); if(!mymirFolder.exists()) { File noMedia = new File(mymirFolder.getAbsolutePath() + "/.nomedia"); noMedia.mkdirs(); noMedia.createNewFile(); } return mymirFolder.getAbsolutePath(); }
推荐答案
我真的在那里?
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) == true
如果针对1.6+,您是否声明
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
?
确切的例外可能会有所帮助.
问题描述
I use the following code to create a folder "mymir" and a file ".nomedia" (in the mymir-folder) on the sdcard of an android unit. However, somehow it fails with the exception that the folder the ".nomedia"-file is to be placed in dosn't exist. Here's the code:
private String EnsureRootDir() throws IOException { File sdcard = Environment.getExternalStorageDirectory(); File mymirFolder = new File(sdcard.getAbsolutePath() + "/mymir/"); if(!mymirFolder.exists()) { File noMedia = new File(mymirFolder.getAbsolutePath() + "/.nomedia"); noMedia.mkdirs(); noMedia.createNewFile(); } return mymirFolder.getAbsolutePath(); }
推荐答案
I SD really there?
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) == true
If targeting 1.6+, have you declared
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
?
The exact Exception could help.