uraj
uraj

Reputation: 439

Creating new files on SD card: Permission denied. I've tried all solutions?

I am sure that I have added permission WRITE_EXTERNAL_STORAGE in manifest.xml, and I have also checked the state of SD card using Environment.getExternalStorageState(), makeing sure the value is Environment.MEDIA_MOUNTED, not Environment.MEDIA_SHARED or anything else. Even with these checks passed, there still is a permission denied error when I try to create new files!

This error only occurs on Nexus One so far. For I myself do not have a Nexus One, I cannot debug it directly. Could anybody help me?

Upvotes: 2

Views: 1530

Answers (2)

Yamanika
Yamanika

Reputation: 31

As far as I was concerned, Environment.MEDIA_MOUNTED returned false and an IOException (Permission denied) was raised because I forgot to add a SD card to my Android Virtual Device.

Upvotes: 3

kalpana c
kalpana c

Reputation: 2739

I think you should try this. Not sure if it will solve your problem:

Environment.getExternalStorageDirectory()

example:

    String path= Environment.getExternalStorageDirectory()+"/yourfilename/";
    File file = new File(path);
    if(!file.exists())
        file.mkdirs();

Upvotes: 3

Related Questions