How to package my android app with a database - android

I've already created an android application that has got an already existing sqlite 3 database within it's asset's folder. I designed the application to copy the database on to the mobile when the app is launched for the first time. My question is how can I ship the database and the app so that users can easily install the app?
thanks

The method I'm going to show you takes
your own SQLite database file from the
"assets" folder and copies into the
system database path of your
application so the SQLiteDatabase API
can open and access it normally.
Have a look here : Using your own sqlite database in your Android applications

Related

Android - How to find my rooted path

I am creating a new app using phonegap (html and javascript) and am using an SQLite database. Due to phonegap limitations and my need for a dynamic database I am following these steps:
1 - creating an external database
2 - exporting this with the .apk file
3 - on app load I replace the phonegap database with my database
The issue I am having here is working out whether 'LocalFileSystem.PERSISTENT' or TEMPORARY. It looks like it is persistent. However, I am not sure how I can root my device allowing me to access and replace the database within the relevnt 'LocalFileSystem.PERSISTENT' section.
Thanks
By default your SQlite database is created at:
/data/data/Your Package/databases/your database
For using already created database see this.

Android database on phone

I have a problem regarding android database.I have an app which have it's database in assets folder.This app is already installed on the phone and working fine.But now i created another database file(just increase the number of records in the previous database and everything else is same). And put it again in assets folder and replace it with existing database file, and recompile the project. Now in emulator the new database is loading and showing the updated content in database. but when i installed the app again in phone my previous database is showing up and new database is not loading.
But if i uninstall the app from the phone and reinstall it then new database is showing up.
PROBLEM: I just want that if i replace the preexisting app on phone the new database should be loaded, not after uninstalling and then reinstalling the app.
Any suggestion or help?
In Android you must use the onUpgrade function to update your database from a previous version. This is because Android will only create your database once and from then on out it will just use that one. So you must assign a version code to your new database that is different from the old one and use the onUpgrade to actually perform the change to the new database. All devices that are installing from scratch do not have a current database so they are getting the new one created for them.
I bet if you clear the data for your app in Settings and relaunch it, it should load the new database. The reason for this has something to do with SQLiteOpenHelper copying the database from the assets folder in the APK to the application's data directory on the phone if it doesn't already exist. Otherwise it will load the one on the phone. Unless you specifically access the database from the assets folder each time, it will use the cached version.

How can I open a SQLite database in android?

If I created a database using another application not through android runtime, let's say using 'SQLite Manager'(firefox extention), how can I then use that database (the .Sqlite file that is generated) in my android application?
Since the SQLite is native in the android not an outsider database.
you can do it by preparing database file(.sqlite) from Sqlite Manager(firefox extention) and then use it in android see example

How can connect Sqlite2009 Pro Database and Android Application

I use Sqlite 2009 pro (Sqlite3 Management Studio) to create new database and insert data. My problem is how can I connect this database and Android application . When installing android application in phone, how can put database with application ?Please help me.
I'm assuming you are creating the database outside of Android. With this method you will simply copy the database to the applications folder (after installing your application), and then you should have it for use.
Create your database (lets call it mydb.db)
Install your base Android application (no db)
Open a command prompt, and cd into the directory with your mydb.db
Type adb push mydb.db /data/data/com.my.app.myapplication/databases
This copies your database that you created to the proper folder that your application should use for your databases (this is my folder structure on 2.2/2.3). Now in your java class, when you specify the database name, it should be mydb.db.
Generally you want to have all of your creation and update scripts built into your program. Using the Management Studio can be handy at first to design the db, but ultimately you'll want to use SQLiteOpenHelper to handle create/drop/update scripts. See this and this link for help with the SQLiteOpenHelper class.
NOTE: I just realized I am doing this on a rooted device, and you MAY not have access to copy to the /data/data/com.my.app/... folder. If you don't, then you might have to find some writable folder to put your database, and somehow access it. Or just use SQLiteOpenHelper :).

Updating only SQLite database file of application without replacing application code and other files on air

I am developing an android application with inbuilt SQLite database. I need to replace SQLite database file only every 3 months. while doing this I should not alter any part of code.
Also I don't want to do this as upgrading application where changing app version I can replace old application with newer version and new database.
For example if I give a button "Update Database" and after clicking this button only database file is replaced using internet and other parts of application remains intact.
simply do as you'd do with any file:
Download the database file from a web server to the devices temp directory (or cache or SDCard)
Move that file to your application's data directory
To do that automatically, you should use a service started by the AlarmManager.

Categories

Resources