The database file is identified by Dalvik when I insert it via the Dalvik Debug Monitor Server (DDMS), but when I add the database to the project assest it doesn't even upload to the device (as I can see through the DDMS). How to fix it?
Adding a sqlite db to the assets folder will not make it available for you to use it.
Your db should be copied to /data/data/YOUR_PACKAGE/databases/ on the first run.
Check this link.
Related
In my android studio in data/data/com.../databases there are 3 files .db, shm.db , wal.db and when i save that .db file it is not showing any table.
While in my another mobile phone files there are only two .db, journal.db and it is showing the table and data when we save it .
i don't know why it is happening ???
If you want to check the database contents, you need to downlaod all those 3 files, store them together in a folder and then you would be able to check the contents of your db.
Your problem:
You are only trying to download the .db extension file. Thats why the issue is coming!
On later versions of Android SQLite Write Ahead logging is enabled by default.
Write ahead logging creates the Wal file, see https://sqlite.org/wal.html for more details.
When the database is closed then the contents of the Wal file will be committed to the main DB file, there is also automatic checkpointing and you can trigger it manually.
It is possible to disable it on a per connection basis, but if data does not get moved to the main db file when you application has been closed then your code is not closing the database properly.
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.
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.
I want to use my own sqlite3 database in my android project.
I created this database with command-shell line (windows) and exported it with SQLite Database Browser (sql format).
I followed this tutorial and my database can't be open :
go here to see since i can't post image
My package is org.opencv.samples and my DBName is "maif" placed in /assets directory.
So it seems that my exported database is incorrect, can someone helps me ?
I suggest to use this helper to solve your problems: https://github.com/jgilfelt/android-sqlite-asset-helper
I don't believe you can transfer an external database through the file system to Android unless you have a rooted phone. If you have to transfer data you need to use data transfer via HTTP using XML/JSON.
I need to deal with sqlite db placed in asset folder in Android project.
The issue is that usually we create a copy of asset db at runtime and all the queries are done on this copy, but the problem is that when I clear the cache it will remove all updates; so I need to update the asset file not the copy that has been created on runtime.
Can I insert update delete the asset sqlite file?
Actually I want to preserve modifications on DB, and I don't want to loose these changes when clearing application data from settings.
You CANNOT modify resources (assets, raw, drawable, etc.) of an .apk once its built. They are read-only, so what ever goes-in will always remain as it is - until you update the .apk with the newer stuff.
You can not get the old record once you cleared the cache, and cant even update the asset file, once the apk file is generated as it is READ-ONLY. Yeah if you want assistance on how to use already ready database then this link will help you for sure.
Using your own SQlite Database in android applications
And i think if you can copy database from assets folder, then, you can get it from sdcard too. dont know much about it.