Skip to content Skip to sidebar Skip to footer

Android: Ioexception: Permission Denied

I'm creating/saving file on SD card. This is the code: File sdDir = Environment.getExternalStorageDirectory(); public void btnsave_clicked(View v) throws FileNotFoundException, IOE

Solution 1:

From the Android Environment doc

Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String).

In other words, this is not really a good practice (although perhaps you have some very good reason; the context isn't very clear).

Additionally, as Cthulhu and Ted Hopp commented, make sure the permission is in the correct location in the manifest.

Solution 2:

Some SD and MicroSD cards have write-protect switches on them. If yours has one, make sure that it is not write-protected.

Also, after you plug your phone in, make sure you have not selected "Turn on USB storage." This will mount your SD card for access by your PC and disable writing by your device.

You can check this by swiping the notification bar down from the top. Mine says "USB Connected" which is ok, but "Turn on USB storage" should not be enabled.

Post a Comment for "Android: Ioexception: Permission Denied"