Skip to main content

Permission to write to the SD card



I would like my app to archive the application DB to the SD card. In my code I check if the directory canWrite(), and if not then throw an IOException. In this perticular instance, I am trying to copy the db file to the root directory on the SD card, but its throwing an IOException. How can I change the permission on a folder/file to be able to write to it?





thanks





patrick


Comments

  1. You're right that the SD Card directory is /sdcard but you shouldn't be hard coding it. Instead, make a call to Environment.getExternalStorageDirectory() to get the directory:

    File sdDir = Environment.getExternalStorageDirectory();


    If you haven't done so already, you will need to give your app the correct permission to write to the SD Card by adding the line below to your Manifest:

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

    ReplyDelete

Post a Comment

Popular posts from this blog

Wildcards in a hosts file

I want to setup my local development machine so that any requests for *.local are redirected to localhost . The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local , site2.local etc, and have them all resolve to localhost , while Apache serves a different site accordingly.