开发者

mkdirs seems to not work on sdcard in onCreate of an Activity

I am using a method to create a directory structure using mkdirs in onCreate of an activity. Eventhough it returns true and all indiactions are that it should work, still the directories are not created (or perhaps not visible) on the sdcard. What might be the problem?

Update: 1. I have given the android.permission.WRITE_EXTERNAL_STORAGE 2. The method works fine if called from anywhere else other than onCreate, i.e the directory structure is created.

public static void createNoMediaFile() {
    Log.v("myreader",">>>>>>>>>>>>>>> Entered createNoMediaFile");
    File papermag=new File(DigitalEditionConstant.PAPERMAG_PATH);
    boolean isdircreated=papermag.mkdirs();
    Log.v("myreader",">>>>>>>>>>>>>>>>Directory setup: "+isdircreated);
 开发者_开发问答   File noMediaFile=new File(DigitalEditionConstant.DIR_PATH+".nomedia");
    if(!noMediaFile.exists()){
        try {
            noMediaFile.createNewFile();
            Log.v("myreader",">>>>>>>>>>>>>>>>>>> Created File: "+noMediaFile.toString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Directory paths etc. are all checked and ok. This method is called from onCreate of an activity in my project


have you added permission of WRITE_EXTERNAL_STORAGE in your manifest file? see here


here is simple code

File wallpaperDirectory = new File(Environment.getExternalStorageDirectory().toString()+"/FolderName");
wallpaperDirectory.mkdirs();

add this permission in your menifest...

permission of WRITE_EXTERNAL_STORAGE


does the name of the dir start with a period? DDMS and most file manager apps wont show those dirs..but they are there.

Have you added the manifest permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Having the device mounted as USB will block access to the SD from code also.


Use "adb push" command to check if you are able to copy the directory to the SD card (to determine that there is no issue with the SD card)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜