how to save static database android app on separate folder - android

I have created a database android app for my college that stores students records and all the record are store in sqlitedatabse and the file name is STUDENT.sqlite.But that file is hidden and can be seen only if phone is rooted.so i need a solution so that the aap gets install it should show separate folder for it and the sqlite file mustbe there in it.so that when i put all records in that and save i can give that file so another person and he can view the same record.no need of entering all records again he can just change the sqlite file.

Maybe you can copy all records from your database into a public or shared directory on sd-card?

Rename the database file to yourdatabase.db and put it in your projects assets folder and on first run of application just copy that database to data directory of android system.

Related

replace database file from assets by the database from data folder

i have a database file "myDB.db" (it have only one Table), and i put that file to assets folder, my app copy the data from it, i can read data there is no problem, but when i try to add a new ROW in my Table the new row only existing in data folder that mean if i clear data or reinstall my app i lose my new ROW. how to add that ROW to my file in assets folder "myDB.db"? or how to replace the new database from my data/data folder to my old file "myDB.db" in assets folder?
i use this code
sorry for my bad ENGLISH.
You cannot do that in the app. Assets are read-only.
You can modify the database on your computer and replace the source version of the asset that gets bundled in the APK.
For versioning preinstalled databases and without the problems with the code you're using, consider sqlite-asset-helper.

Android database location in app directory

I don't understand why database files are stored in the android emulator or phone in the data folder data/data//databases rather than being stored in the application that uses it.
Logically, the database file must also be stored in the android app, right ?
If yes, where should it be stored in the app directory ?
your database will be saved under data/data/myApp/database and not in any other folder but your application folder, since database consider as a private to your app, android make it hard for people with non-root access to see your database. you still can store it in any place you like just point to it from your app.
Put your database in your assets folder, then its path is given by "/data/data/<your-package-name>/databases/<dbname>"

Best way to populate SQLiteDatabase with initial data?

Say I have data about customers and I initially have around 1000 pre-determined customers details I want to insert into my SQLiteDatabase.
Would it be wise to store that data into a text file in my assets folder with my own formatting (tabs to indicate columns and new lines to indicate rows), then just read the text file and insert the data into the database with insert statements? I feel this is not the best way and very in-efficient.
Is there a better way of doing this?
You can use the utility to create your SQL Lite database offline on PC, such as this:
http://portableapps.com/apps/development/sqlite_database_browser_portable
You can package this database along with your app and then put it on phone storage and continue from there.
You can do do in two ways..
Way 1:
You can make one .sqlite file with already 1000 customer records inserted in database and you can use it that .sqlite file from assets folder. Then you can copy those records in your internal database or use that only database.
Way 2:
You can put this 1000 records on server and call it by web service at first time app is launched..
Hope it will help you.
User a .sqlite or .db file in your assets folder with prelaoded entries and import this file to you app from asset folder.
You can use this add-on to access and create you db file
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
and this is tutorial to access database file from assets
Android: Accessing assets folder sqlite database file with .sqlite extension
I would bring along the already pre-populated database .db file.
I've done this before with "sample" data included as part of an application.

Should I explicitly create SQLite tables in my app?

I am a novice, and am creating a simple app that just reads data from a table in an SQLite database and displays on the GUI. (Just select operation )
During development, I created the database and the table from the tool "SQLite Database browser". And I inserted all data into the table through the tool.
Now, my doubt is ..
1) In java code, should I have some method that creates database and table ?? (For now, I have methods to do the select operation alone)
2) The database I created is located in my local drive. When the apk file gets created would the database also be included in the apk file ??
Pls help !! Thanks in advance !!
1) In Java code, should I have some method that creates database and table ?? (For now, I have methods to do the select operation alone)
No, You have to just copy your database file from /asset directory to /data/data/<package_name>/database directory. And only use select operation alone. You don't need to use create Database and table operation..
2) The database I created is located in my local drive. When the apk file gets created would the database also be included in the apk file?
For this, as I mentioned above you have to first put your database file into application's /asset directory, then copy it to internal storage (when your application start), then it works.
Look at this SO question How to ship an Android application with a database?. It answered what you needed.
try below link
http://www.higherpass.com/Android/Tutorials/Accessing-Data-With-Android-Cursors/

How to create sqlite database at the time of android app installation?

I am having Registration screen as my first screen but before that i want to create database. is it possible to create database at time of installation in android rather than creating in first activity.
This is a great article that helps http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Create the sqlite db using SQLite Database Browser and store it in your assests folder
When app launches, copy the db from assets to your apps data directory
Open the DB
This way you don't have to parse csv files or dynamically create the db on the device, saving time during first load.
If you want to use a previously created database in your application,at the time of installation the you need to create a database put it in assets folder and then copy it in application.
refer this links:
SQLite Database "context" passed to adapter
Database not copying from assets
adding your own SQLite database to an android application

Categories

Resources