Android open or create database -
i trying create database on sd card. whenever call sqlitedatabase.openorcreatedatabase error:
07-21 13:33:17.587: error/androidruntime(5541): caused by: android.database.sqlite.sqliteexception: unable open database file
does know may causing this? here code have in open() method of database class:
file sdcard = environment.getexternalstoragedirectory(); string dbfile = sdcard.getabsolutepath() + file.separator+ "external_sd" + file.separator + schema.database_name ; db = sqlitedatabase.openorcreatedatabase(dbfile, null);
one possible fault on did not set appropriate permissions
<uses-permission android:name="android.permission.write_external_storage" />
however storing data on sd card considered insecure. because every application has permissions store data on sd storage access database.
edit: possible problem external storage may not available. need make sure external storage writeable. 1 method determine state via getexternalstoragestate
(see reference here).
getexternalstoragestate() returns media_shared if media present not mounted, , shared via usb mass storage.
reference. there stackoverflow post on checking state here: writing text file sd card fails
Comments
Post a Comment