I'm working on a small Android database application (I'm an Android newbie). I have an existing sqlite3 database created on a different platform. When I use it my SQLiteOpenHelper always calls OnCreate (which of course fails). When I let Android create the Database all works just fine - OnCreate is called for the first time, but not subsequently.
The android_metadata table is present with local=en_US.
What's going on?
What do you mean by different platform , do you mean different android application ? If thats the case and you need to use it in this application, you would have to expose your database like a content provider to this application.
#xandy If you are doing Android development on eclipse platform then do the following.
goto DDMS --> File Explorer --> data -->data --> Your application --> create database folder if not exists.
Then there is an option for "Push a file to this device" push your database file in that. :)
Hope it helps :)
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'd like to create a project which generates a sqlite database, which will eventually be used by an android application. I'd like to create this project as a standard java application, so I can hook it up to a build script etc. What's a good way to go about doing this, so that the sqlite database I output is conformant with the way android sqlite classes expect to have it in?
I could create this util project as an android project, and then I have access to all the sqlite classes, but the output sqlite file would live on an emulator instance, right? And I'd have to fire up an emulator etc whenever I wanted to run the util, ugh.
Thanks
As others have suggested, I wouldn't build a project for it, I'd find one of the existing utilities out there and create the DB that way. I use SQLite Expert.
Despite what Seva said, there are some things you have to do to make it usable by android. It's readable in any state, but if you want the framework to be able ot make use of it like intended (to populate listviews and other widgets), it has to have certain things.
1) The database must contain a table called "android_metadata"
2) This table must have the column "locale"
3) There should be a single record in the table with a value of "en_US"
4) The primary key for every table needs to be called "_id" (this is so Android will know where to bind the id field of your tables)
Then you put the DB in your assets folder and copy it to your apps data directory on startup.
A good link for this process is here.
Why do you want create a separate Java project to create a SQLite database? There are graphical shells over SQLite out there. I personally like SQLiteStudio.
There's nothing special about the way Android accesses them - SQLite is SQLite, the database format is the same on every platform. Create a new database file, create some tables in it, insert some data, then place it into an Android project and play with it.
can create you other as libray project and can attach it with your project...libaray project may be an android or simple java project as per your need...
Note: use the version of sqlite that comes with the SDK -- it's been modified slightly. If you use the off-the-shelf sqlite3 commandline tool, the databases it generates are incompatible with Android.
I have created a table in SQLite using phonegap. How can i have access to this table using Java?
Because i have made a background process (as a phonegap plugin) which needs to retrieve data from the already made table.
Your database is located in
On Eclipse :
Window>Open Perspective>Other>DDMS
-- in File Explorer tab
data>data>your_package_name>databases>your_DB_fileName
So at any point of time if database is successfully create and available in it respective location, then you can read it programatically using the path
/data/data/your_package_name/databases/your_DB_fileName
I've created an Android application which has a certain package name that I've been using personally for months now. I'm about to release it on the market, and I have to change the package name. This cannot be avoided.
My issue is that the application has an SQLite database attached to it that I want to keep, but I know if I change the package name, it'll install as a separate application and I'll have to restart my database, which would take a very long time.
Is there a good way to change a package name while maintaining the SQLite database? Or at least moving the database easily? This will just be for my own phone since it hasn't been released to the public yet.
Step #1: Add a backup/restore function to your app, that copies the database to/from the SD card. Be sure your SQLiteDatabase and SQLiteOpenHelper objects are closed first.
Step #2: Install a copy of this app, built with the old package, to your phone, and use it to back up your database.
Step #3: Install the production copy of this app to your phone and use it to restore your database.
For anybody wanting to do the same thing, I've written out how to do backup/import/restore of a database and included a whole class for doing it at this link:
http://www.hxcaine.com/blog/2010/09/14/backing-up-importing-and-restoring-databases-on-android/
There are some things my application needs to do on first start up(first startup after update) . These actions could be described in a .txt file and then when it is the case read the file and do according to it ,or on the other hand (I lean to use this option) a sqlite database could be used to store the information . The apk file would be shipped with an .txt file/prebuild sql db stored in res/raw or res.asset and then copied into proper space and used. This I have figured out how !, though I'm not sure which option of this two would be the fittest ? One thing that is unclear to me is how could sqlite version mismatch affect me, and if it serious enough to take into consideration ? I 'm using Android api level 4 (Android 1.6) and the future application might be used on several different devices , with different api levels.
These actions could be described in a
.txt file and then when it is the case
read the file and do according to it
,or on the other hand (I lean to use
this option) a sqlite database could
be used to store the information .
Or, they could be implemented in Java.
Well the actions that the application
needs to perform on install / after
update , according to the update
version and the pre update version of
the application
Why not just implement this as regular Java code in your app?
Or, as Albert Einstein wrote, in homage to Occam's Razor: "Make everything as simple as possible, but not simpler."