Read More
Read now

How to ship your application with a default database in android

Save

In this blog, I am going to show you how to ship your default database with your application.

So let’s Begin!!

What that means

When you have an Android app that has a built-in database.  The more Cleared way, you have pre-created the SQLite database and include it in the APK. Whenever your application runs it uses the same database which you have included in it.

 

What to do

There are some easy steps for shipping your application with a built-in database.

  1. First Create your database file. And Export it. You can use SQLite browser or Android-Debug-Database(if you are using room) and if you are using realm database you can use the Stetho.
  2. After successfully create and export database, copy it to your assets folder in your application.
  3. Then copy your database file from assets folder to your android database location, “/data/data/” + BuildConfig.APPLICATION_ID + “/databases/”;
  4. Before copying your have to check is database already exist, if yes then no need to copy the DB until the new version exists, else copy your database on to the database location.
  5. Voila!! You have successfully shipped your application with pre-loaded Database.

 

How to do

Step 1: Create your database and create tables that you want to be in the application by default. And then export it using any DB browser or you can do it manually.

Step 2: Copy your .db file in your assets folder,

 

Step 3: Copy your database file from assets folder to your android database location,

 

Step 4: Checking is database already exist or not,

If not exist put your preloaded db file in that. And create your app.

Bravo!!! You have successfully shipped your application with your default database.

Thanks for reading this Technical blog, I Hope this is helpful for you. If you got any query or issue please ask me on the comment below.

Stay updated and Stay Cool. 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home