I apologize if this is a stupid question, nevertheless I need to ask. I am new to Android development and have gone through every single tutorial and reference provided. I have been doing great, with the exception of one stupid problem; I cannot find where the databases for some apps are stored.
For example I would like to build my own app that includes thousands of pre-made records from an established SQLite Database. As a reference I tried to use the "Searchable Dictionary" app from the provided programs in the Android SDK, but cannot find it.
I read that all databases are stored in /data/data//databases on the device, but I cannot find this location. So how would I access the database in Eclipse or anywhere else for that matter to set up my pre-configured database?
Thanks so much!
not directly in eclipse, but sqlite db browser is petty nice http://sqlitebrowser.sourceforge.net/
Assuming your package for your app is com.example.androidapp and the database name is db you can do the following:
adb shell
and then in the command line shell
cd /data/data/com.example.androidapp/databases
sqlite3 db
and then in the sqlite3 interface e.g.
.schema
or
SELECT * FROM tablename;
and so on.
Related
I have an Android app where I use a SQLIte DataBase. I am using the app and the DB is already big. Now I want to give this app with its DB to my coworkers. Where and How to put the DB for release? I have the DB in my phone but I need it in assets folder. I was trying but it doesn't work. I tried to copy the DB directly however I read that Android compress files in that folder. Please, any solution, thank you in advance.
http://blog.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Visit this link. It contains the easiest and well described answer for your question.
You can use emulator Like GenyMotion and any other emulator. Run your app on emulator then just go to Android Studio->Tools->Android Device Monitor Then select the emulator and in the file Explorer you can find your db file . and then export from the device and export to your desktop. here you can give it to any one.
You can use your own SQLite database by adding it to assets folder. The best way is to use Android SQLiteAssetHelper. Better than reinventing the wheel.
Here the excerpts from its readme:
An Android helper class to manage database creation and version
management using an application's raw asset files.
This class provides developers with a simple way to ship their Android
app with an existing SQLite database (which may be pre-populated with
data) and to manage its initial creation and any upgrades required
with subsequent version releases.
It is implemented as an extension to SQLiteOpenHelper, providing an
efficient way for ContentProvider implementations to defer opening and
upgrading the database until first use.
Rather than implementing the onCreate() and onUpgrade() methods to
execute a bunch of SQL statements, developers simply include
appropriately named file assets in their project's assets directory.
These will include the initial SQLite database file for creation and
optionally any SQL upgrade scripts.
i just want to know how to get the android loacal-app Contact' database,i want to check the raw_contact or data table with terminal.what tools i need or what is the orders?Thanks.
From what I understand from your question you want to use a CLI tool to inspect the Android contact's database. AFAIK the database itself should be located in
/data/data/com.android.providers.contacts/databases/contacts2.db
But could possibly change depending on the manufacture?
As far as using a local tool on your Ubuntu install you'd first need to get the platform SDK to use ADB to pull the database off your device then use a local tool to manipulate or examine the database. Note:Your device will need to be rooted to pull the database.
For example on the SQLite website they provide a binary for Linux to inspect databases. It can be located here: http://www.sqlite.org/download.html but I'm sure there are a couple more floating around due to SQLite being an open standard.
Hope this answers your questions.
Im REALLY struggling to get a pre baked db4o database to work inside my android app.
If i include it in the /res/raw folder then read it, it doesn't work.
If i copy it to the app_data or sdcard then try and read it, it will act as if im opening a new database and provide me with 0 entries on queries.
I was previously just creating all my entries when the app was first opened but as the db grew, so did the creation time to unsustainable levels.
I would really, really appreciated any help you can give me. It would be perfect if i can include my pre-populated db4o file in the app.
Additional Info:
I have double checked the db4o file with ome and theres no issue with the db creation on my local machine.
Thanks in advance.
If any one falls into the same trap as me here's the answer:
On android the class is injected into the db4o db with the package name prefixed to the class name by defualt. So accessing from another application will look be looking for +.
I want to monitor the contents of my database during debugging, i.e, I want to see all the rows in the tables, and see the updates as and when they take place. Currently, I'm using android.util.Log. But, if there is a better way to do it, that would be nice. Thanks.
The database file is in the /data/data/package_name/database
You can:
use adb shell, use command "sqlite3 your_database" to manage the database, also there exists a tool in sdk called sqlite3 (a command line tool)
push the database file out, use a sqlite browse tool to check for details (tools such as sqliteadmin, sqlitebrowser)
I asked the same question before: Logging SQL statements using SQLiteDatabase . Seems like there's no decent logging tool for SQLite on Android. It is a real shame.
Some of my users are reporting that they cannot correctly open sqlite databases created in Android using sqlite jdbc or other tools like sqlite browser (http://sourceforge.net/projects/sqlitebrowser/).
Here is an example database with the problem:
http://pocket-for-android.1047292.n5.nabble.com/Desktop-Version-Screenshots-Work-In-Progress-tp4383220p4456017.html
This sqlite db was created on a HTC Sensation, running Android 2.3.3 and Sense 3.0.
The exact problem is that if you look at the file in a text editor you can see a bunch of tables being created but if you try and run "select * from groups;" you will get an SQLException: file is encrypted or is not a database.
I have tried using "select sqlite_version;" to see if it is a versioning issue - the sqlite browser says 3.6.18.but different tools give me different version numbers... not sure what is going on with that.
I should also point out that my app copies the db directly from the device (/data/data/com.citc.wallet/databases/wallet.db) onto Dropbox.
Any help would be really appreciated.
The solution was that the zentus project is not working with the latest versions of SQLite.
Fortunately someone is keeping a fork maintained here: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC
All I had to do was replace the jar with the xerial one and it all worked. Xerial sqlite jdbc is in my opinion the best way of connecting to SQLite in Java (I tried several of the libs).
I am also getting the same problem.
But once I have changed the database name it resolved.
So, just try it by creating new database