Nijan
Nijan

Reputation: 93

Android: SDcard permission denied

I tried to write Log in my application, I am getting following exception in some of the Android devices alone, /mnt/sdcard/Log/log.txt: open failed: ACCES (Permission denied). I had used WRITE_EXTERNAL_STORAGE permission also, but i am getting this error.

File sdCard = Environment.getExternalStorageDirectory(); 
File dir = new File(sdCard.getAbsolutePath() + logDir); 
dir.mkdirs(); 

File file = new File(dir, logFileName); 
PrintWriter writer = new PrintWriter(new BufferedWriter( new FileWriter(file, true), 8 * 1024)); 
writer.println(message); 
writer.flush(); 
writer.close(); 

Please help me, Thanks in advance.

Upvotes: 0

Views: 950

Answers (2)

1011
1011

Reputation: 121

Do you have proper permission in the AndroidManifest.xml file. If so then may I see the code that you used to save write the log.

Upvotes: 0

Junaid
Junaid

Reputation: 7860

Dont hardcode the sdcard, you must use Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)

will let you know if the memory is loaded. Then use:

Environment.getExternalStorageDirectory().getAbsolutePath()

Upvotes: 2

Related Questions