SQLite - Can I send a database file with application? - android

Pretty simple question, can I send a already created database (a file, for instance) with my application?
Or do I have to create it inside my application?

Yes you can do both. Either create on 1st launch or copy preconfigured database from assets.
For the latter option (which is basically significantly faster if you need your database to be pre-populated) you can use Android SQLiteAssetHelper to do all the job.

you may put it into the assets/ folder and copy into the SQLite on the first run.

Some apps include an SQLite database in the assets folder, and copy it when the app is launched.

Related

Push db file to Databases folder in android

I wondered If it is possible to push db files into databases folder of an Android application either programatically or using any tool.
Thanks in advance!
Yes you can but not directly.
Typically a pre-built database would be included as an asset and copied to the databases folder for the package when the App is first run after installation.
If using this method then you should consider using SQLiteAssethelper, as using this simplifies the process.
In one of my App's I introduced a back-restore that backed-up the database and could restore from the downloads folder. If need be I can copy a database from elsewhere into the downloads folder and restore from that within the App. However obviously such a database has to have the correct structure/schema to not result in errors. So that is another way but would be at the user's discretion to do.
Obviously data/data//databases is protected so that imposes restrictions on "Pushing" data directly into the folder.

Backup SQLite database and restore it back when the Android application is installed

I am building an Android application that fetches data from a cloud database and stores it in SQLite locally so that user does not need to fetch it again and again.
Now I need to find an efficient way to predefine a few rows in the SQLite database and provide it along with the APK. Is this possible? if so, how do I achieve it?
Yes it is possible.
You follow these steps :-
You create the database externally, populating it, and copy the file to your App's assets folder.
You may have to create the folder.
If using Android SQLiteAssetHelper then you will need to create a databases folder in the assets folder.
There are various tools for Creating and Managing SQLite Databases. e.g. Db Browser for SQLite.
You then need to modify your App to copy the file from the assets folder (or assets/databases folder) and then open the database. Noting that you only do the copy if the database doesn't already exist.
Using the Android SQLiteAssetHelper simplifies this process.

Android - Best way to using SQLite?

I am developing an app in android which consists of activities that need to connect to the Database . I added my database file in assets folder which gets copied over to applications database directory on first time the app runs but "assets" directory and "data" directory(on rooted devices) can be accessed by any other application . I'm confusing between using database file or create database in code . If i create database in code it make the database file disappear in the "assets" folder . When users change the file extension from .apk to .zip ,database file will not appear in assest folder . What I should to do ?
Please give me some advice !
Both ways are good and useful it completely depends on your need.
By creating database in code you can secure your data from other applications but it will take so much pain to create it in that way so i suggest you to use a db or sqlite file in assets folder and while copying database on device or data folder use some security parameters to encrypt it or you can hide your app database folder on device so other applications and users will be not able to access it easily.
Well keeping Database in assets folder is not at all a bad practice plus it saves coding of creating a database , as far as you want to make it secure you have to do 2 things
1.keep you database in assests folder , and copy and save it in the internal memory , now its available only to your application and delete it from assests folder .
2.Use Proguard to protect it from somebody decompiling your application and obtaining the assests.
And yea if its a confidential data in the application and your application is worth it then you can also go for "encrypting data" but yea its a TDS task , see for yourself what suits you now.
Honestly, this is the best explained and a very complete tutorial on the subject
SQLite Android Tutorial
Don't get repulsive, because it's a bit longer one. Everything is explained nicely and you don't have to do the thinking about the location of your asset folder on different devices and so on...

How to distribute Android app with DB data?

I'm writing my first serious Android App, which basically is interface to three DB tables.
Data in those tables are predefined by me, so, user should install those app with those data.
What is the best way to include those data in application package? Maybe there is a way to embed SQLite into my application distribution?
Or is the only way is to define array of "insert into" strings somewhere in class and execute them to fill internal SQLite storage?
Would appreciate any recommendations.
I am currently doing the same thing in my app. Having a sqlite database file in my assets folder and copying it into the SD card at startup if it's not in there. There's a nice tutorial there and I use part of its code.
Put the database file in your assets and then copy it over to your application's data directory.
Your can check out this tutorial

how to open Iphone's database(created) in Android?

Database is created in Iphone using SQLite.Now I want to use same database file in Android and insert the data into tables.How to do that?
Android Developer
The easiest way is to copy the file in your applications folder say assets folder and copy the database from the local file, first time the app is loading.
this link will give you a solution.

Categories

Resources