After exporting Android apk file, there is no data included in SQLite database (I mean, empty database only attached).
put your filled database in asset directory and programatically copy that database in
data/data/<package name>/database directory when your application runs.
EDIT :
look at this my answer,
Not empty LiteSQL DB at start.
The following stackoverflow post may answer your question:
Updating prepopulated database in Android
In addition the following blog entry (based on the above answer may be useful):
http://blog.luxteam.net/2011/01/04/prefilled-database-in-android-application/
Search goggle for "Prefilled Database Android" may also get you some relevant results
Related
I have an Android app where I use a SQLIte DataBase. I am using the app and the DB is already big. Now I want to give this app with its DB to my coworkers. Where and How to put the DB for release? I have the DB in my phone but I need it in assets folder. I was trying but it doesn't work. I tried to copy the DB directly however I read that Android compress files in that folder. Please, any solution, thank you in advance.
http://blog.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Visit this link. It contains the easiest and well described answer for your question.
You can use emulator Like GenyMotion and any other emulator. Run your app on emulator then just go to Android Studio->Tools->Android Device Monitor Then select the emulator and in the file Explorer you can find your db file . and then export from the device and export to your desktop. here you can give it to any one.
You can use your own SQLite database by adding it to assets folder. The best way is to use Android SQLiteAssetHelper. Better than reinventing the wheel.
Here the excerpts from its readme:
An Android helper class to manage database creation and version
management using an application's raw asset files.
This class provides developers with a simple way to ship their Android
app with an existing SQLite database (which may be pre-populated with
data) and to manage its initial creation and any upgrades required
with subsequent version releases.
It is implemented as an extension to SQLiteOpenHelper, providing an
efficient way for ContentProvider implementations to defer opening and
upgrading the database until first use.
Rather than implementing the onCreate() and onUpgrade() methods to
execute a bunch of SQL statements, developers simply include
appropriately named file assets in their project's assets directory.
These will include the initial SQLite database file for creation and
optionally any SQL upgrade scripts.
I'm working with Visual Studio 2013 and the Cordova Tools package.
I have most of my app working, and I'm now ready to add the DB logic. I have a DB full of quotes, and I need to tie that into the app.
Following this link: adding dynamic data with SQLite
I was able to get SQLite to talk to a DB (using the sqlitePlugin) However, I can't figure out how to use a pre-populated DB. It always created a new empty DB. I've found several articles on the web that keep saying "put the db in the www folder"... but the Cordova project doesn't have a www folder.
Putting the SQLite DB file in the root doesn't work, and I tried using a path and putting it in a sub-dir. No luck there either.
Has anyone been able to make this work?
Old question, but I will answer to serve as a reference: I solved this problem by changing the plugin. Previously, I was using plugin cordova-sqlite-storage (https://github.com/litehelpers/Cordova-sqlite-storage), but it doesn't copy the prepopulated database. It always creates an empty one.
After days of fighting, I uninstalled the plugin and installed this one: cordova-plugin-sqlite (https://www.npmjs.com/package/cordova-plugin-sqlite). This one works like a charm, it will copy the DB in the www folder to the device. Just follow the instructions and don't forget the createFromLocation parameter.
The strange bit it that both plugins are from the same author, and both seem to be active projects. Go figure.
Old question, but I will answer to serve as a reference (2)!
Pre-populated SQLite is supported by cordova-sqlite-ext project.
The steps are simple:
put the database file in the www directory and open the database like: www/sample.db
Then, use:
var db = window.sqlitePlugin.openDatabase({name: "sample.db", createFromLocation: 1});
More information: https://github.com/litehelpers/cordova-sqlite-ext#pre-populated-databases
Many sites and answers point to use Cordova-sqlite-storage for this. In fact, this feature was in this project, but it was moved to Cordova-sqlite-ext (they are from the same creator).
I don't recomend using cordova-plugin-sqlite. It is deprecated.
I've been trying(for days now) to get an Android map app working. This app has to work offline and im only interested in displaying a small city, after seeing all of my choices and trying them all, it seems that Nutiteq is a great choice, specifically the offline MBTiles option. After setting everything up, and using a .mbtiles file downloaded using TileMill, i get the following error:
No such table android_metadata
The .mbtile file i downloaded doesn't have this table, and i can't find which class made this query(if anyone can explain why it's needed great!!!); i tried updating my .mbtile file with Navicat to add this table with the desired locale column with the en_US value, and now it gives the following log error message:
can't upgrade read-only database from version 0 to 1
My questions are:
Is there a way to bypass this whole android_metadata query? I mean, if it's not included on the .mbtile why is it needed afterwards?
If you don't recommend bypassing it, how to fix my second error with the upgraded database?
Thanks.
Are you trying to modify the database during the upgrade? If it's readonly, you probably can't modify it. You could create a new one, though, and copy the data from the old to the new.
Im REALLY struggling to get a pre baked db4o database to work inside my android app.
If i include it in the /res/raw folder then read it, it doesn't work.
If i copy it to the app_data or sdcard then try and read it, it will act as if im opening a new database and provide me with 0 entries on queries.
I was previously just creating all my entries when the app was first opened but as the db grew, so did the creation time to unsustainable levels.
I would really, really appreciated any help you can give me. It would be perfect if i can include my pre-populated db4o file in the app.
Additional Info:
I have double checked the db4o file with ome and theres no issue with the db creation on my local machine.
Thanks in advance.
If any one falls into the same trap as me here's the answer:
On android the class is injected into the db4o db with the package name prefixed to the class name by defualt. So accessing from another application will look be looking for +.
I have made a sample.sql database with "SQL Lite Manager".
How can I access this in an Android project?
Put your prebuild database file in /assets directory in your apk,
and on first use copy to "/data/data/<application_package>/databases/" directory.
Now use it with SQLite Database Helper class in your android application...
For more info look at this Article
There are several steps to using an existing SQLite data base in an Android project. They are nicely described in this blog post by Juan-Manuel FluxĂ .
Basically, you need to make sure that the data base contains certain tables and column names, then when your program first runs, copy the data base from your assets or resources folder to the standard db location for your app. The latter step is best done by writing a DataBaseHelper class the way that FluxĂ describes.