Offline database inclusion in Android apk on real device - android

I have a question regarding creating an android application for travel guide. I am creating it offline. I am familiar with the problem that we access the database on the real device. I want an external database file in which the data is already filled. I just want to include this database in my apk and just want to access that database in my phone offline. I am using SLQite database. I had imported db file from assets folder. It works on emulator but not on a real device due to no access to system files.

I think this blog post does what you want to do. I am using this approach in my applications for a while and I am satisfied with it.
It is fast and relatively easy.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

I have included the db in assets folder and the db file is copied in the path sdcard/Android/data/packagename/test.db on a real device..now I am accessing the db, it works fine on emulator but when I used it on a real device it get crashed.the db is still not working on real device.

Related

Access SQLite DB from IntelliJ for Android

How can I view the DB in IntelliJ to view its content and perform operations on it. Now I have created my tables etc but i have no idea what data is on the DB and I do not want to create queries in java to check it. seems like a slow workflow so ill wait til I know how to access the db that resides on the Android emulator im using.
Is it possible?
You can also use Stetho. A nice debugging tool from Facebook.
Just simple to use, initialize it in your Application class and access your sqlite and even shared preferences from Google Chrome's developer console.
You can create a database file outside of Android and use any tool to create and read it.
Then, you place it in the assets folder and setup your code to read the database from there instead of private app data. Caveat here is that a copy will be made from the assets folder to the app data, so any updates within the app won't be mirrored to the database file in the assets folder.
I believe you can access the DDMS window in Intellij/Android Studio and there is a Database Explorer there
see #alexsimo's answer.
Without root you cannot access your database on your device, unless the file is created with a+r permissions.
Since that is something that is unrelated to the issue, you can just search in plugin.jetbrains.com for sqlite and get a variety of plugins.

Database created from SQLite Browser not working in device "Android"

My proble is I created a device in sqlite database browser and its work fine in emulator.
but when a try my application to my device it cause force close.
and when I remove the database and create a new one using eclipse it works fine even in my device. But inserting a lot of data in database 1 by 1 realy freakin me out so anyone know a sqlite database browser that also work for device??!
check out this tutorial for using database file in application.
Remember one thing that it only copy you DB file in application that's it.
On real device you don't have permissions to sqlite database. That's why you won't be able to browse database like you can on a emulator.
See this for a work around.
Tool to see android database, tables and data
If you want to create a pre-loaded DB outside of your app and use it in your app later, you will have to put it in your assets directory and then copy it to your apps storage space the first time your app is started.
This is due to the fact that as a security measure, on real (unrooted) devices nothing but your own app is allowed access to that apps databases directory (and certain other ones as well).
There is a good tutorial for creating/copying your own DB outside of the app and copying it to the apps databases directory here.

Android SQLite path

I am working with SQLite in an App. It writes to the database, etc., with no problem. However, I can not find this new database. I have tried changing the directory with cd /data/data/packageName/databases, but it says "no such file or directory". Also, this database is not found when I click on the File Explorer in eclipse. My logging tells me the database was created and that it is being written to. I think I need to set the path in the shell or something to that effect using adb, but I have no idea how to do that. Can anyone give me some instruction? Also, I am using my phone for development. The database also does not show up when using the emulator.
Thanks very much.
Matt
Matt,
This thread gives a good explanation on why you might not be able to access the data folder on your phone.
Can't access data folder in the File Explorer of DDMS using a Nexus One!
You can still test the Sqlite code though. Just boot up an emulator. The emulator will have no access restrictions. Once it's booted up you can use the ddms tool (located in the tools directory under your android SDK install folder). It has a File Explorer and you can download the files from the /data folder.
Also, I am using my phone for development.
You cannot access the database on a standard Android device except via your own application code.
Your options are:
Do this sort of testing on an emulator, in which case you can access the directory that you are failing to access on the device
Add a database backup feature to your app, that copies the (closed) database to external storage, so you can examine it
Root your phone (leastways, I am under the impression this can help get you to this directory -- haven't done it myself)
The database also does not show up when using the emulator.
Try harder. If you can store data in the database and read data out of it using SQLiteDatabase, then the database file is there.

sqlite browser: where is the db file?

I would like examine androids internal database files using a sqlite browser. From my understanding contacts, etc. is stored in an sql lite db on Android. Now I want to read these tables using sqlite browser. For that I need to specify the db file, but where is it located?
The question is where is the location for the emulator?
Where is it located on a real device?
Can I access it on a real device which is not rooted?
All databases are saved in:
/data/data/the.app.package.name/databases/the_name_of_db
And no, you cannot access that file in a non-rooted phone. Fortunately the emulator is rooted.
Open your application with emulator and go in DDMS. Then in FileExplorer go into data/data/application.package.name/databases/name_of_your_database. Then pull it from device

Android App with a database crashes

I've built an android application with a database (sqlite 3) targeted for Android 2.2 with API level 8. It works by copying the database from the assets directory to the /data/data/com.myapp.db/databases folder. It works just fine on the emulator. However, when I try to install the application on HTC mobile device with version 2.2 and 2.1-update1, it crashes. The error says "Failed to Copy the Database". Could this be as a result of the database path that I used on the emulator and the actual device mismatching? I'm eagerly looking for your answers.
Thanks
I think it's a matter of permissions. The application has limited access to the system folder, unless you have your device rooted. The database you create from your application is saved under application directory. Maybe i didn't properly understand your issue, but... you are not creating a new database, but just moving a database you have in your assets to a final directory?. Where does this database in assets come from?. Why don't you create your tables in the Android application?

Categories

Resources