I've got a project using Cordova (ionic framework) with ngCordova and the cordovaSQLite plugin. The plugin is installed, js has been added to the html, WRITE_EXTERNAL_STORAGE permission added to androidmanifest, and the following two lines in my config.xml
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />
However, when I run the example code:
$cordovaSQLite.openDB({name: "wt.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
I get the error E/cutils(1910): Failed to mkdirat(/storage/usbdisk0/Android): Read-only file system
I checked on my Android device (S3 running AOKP), and I have an empty /storage/usbdisk0 but no Android folder in there, and even with superuser I can't create it. I also have /storage/sdcard0 and /storage/sdcard1 and /storage/emulated (with 0 and legacy inside linked to the internal sd card).
I'm assuming the problem is that the default directory the plugin uses to store databases is wrong for my phone, but that means it could be wrong for anyone's phone.
If my assumption is correct, how do I get the plugin to put the database in the right place?
I just read what my config.xml preferences (which I had copied and pasted from some documentation) actually said. The problem was <preference name="AndroidPersistentFileLocation" value="Compatibility" />
which was causing the file to be created in the wrong place.
If I replace both preference lines with <preference name="AndroidPersistentFileLocation" value="internal" />
, I no longer even need to ask for the WRITE_EXTERNAL_STORAGE permission and it works fine.