Reputation: 11
I am trying to build a cross platform mobile app using Cordova/Phonegap 3.5.
First, I am trying to create the Android version using Eclipse with Android SDK.
One of the requirements is that I want my app to be shipped with some database tables created and pre-populated with some data.
I have tried various things so far, but nothing seems to be working.
Here is what I have done so far:
I used github.com/jgilfelt/android-sqlite-asset-helper to create the DB:
public class MyDatabase extends SQLiteAssetHelper { private static final String DATABASE_NAME = "database_name"; private static final int DATABASE_VERSION = 1; public MyDatabase(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } }
Within my main activity I simply invoke the above class, in order to ensure that this gets executed. Is this the right way?
In my HTML file, I am trying to open the database and do some operations with it, as given here: http://docs.phonegap.com/en/3.1.0/cordova_storage_storage.md.html#Storage
As per the above documentation, the window.openDatabase()
function call should return the existing sqlite database and give me a handle to work with it further.
But this does not seem to be happening. When I run my app, it does not give me any error on the LogCat console, but it does not find my pre-populated database either.
Notes
With Cordova 3.5, I am not using any external sqlite plugin, as it is supposed to be in-built in this version. Is this correct?
As a side note - How can I browse my Android device (Nexus 7 tablet) to actually verify that the database has been created?
Thanks so much for any help.
Upvotes: 1
Views: 307
Reputation: 582
Though this question is old... thought it might help someone to post my solution - found in 2017. (Since PhoneGap has changed, older solutions may no longer work or be accepted on the Android and Apple app markets.) I worked on this problem for a long time - the issue about how to import a pre-populated database - which there are not alot of easy solutions for. I found the best - and currently just about the ONLY - solution to be LiteHelpers CORDOVA-SQLITE-EXT (https://github.com/litehelpers/cordova-sqlite-ext)
I have added this in to my app and it is working well. I had to switch away from PhoneGap though - and use CORDOVA - but it is working for me.
Upvotes: 1