View contents of database created with Room Persistence Library

AndroidAndroid Room

Android Problem Overview


Is there any easier way to see the contents of database created with Room Persistence Library in Android Studio?

Android Solutions


Solution 1 - Android

In older Android Studio versions:

Emulator -> Android Studio -> Device File Explorer -> /data/data/{$packageId}/databases/ -> Save As -> https://sqlitebrowser.org/

In later Android Studio versions (3.5+):

View -> Tool Windows -> Device File Explorer -> /data/data/{$packageId}/databases/ -> Save As -> https://sqlitebrowser.org/

Solution 2 - Android

in android studio 3.1.*

in tool window bar click on "Device File explorer" generally you can find this in bottom right corner of the screenn

open directory in data/data/your-application-package/databases

with new architecture 3 files is created in databases directory

your-database-name
your-database-name-shm
your-database-name-wal

you have to export all 3 in the same directory

then open first one file (that is with your-database-name only ) in any sqlite browser.

and now you can see all your data .......

your-database-name-shm
your-database-name-wal

these two extra files are needed to open db file if you will open database file only, than you will not found any table in that file

Solution 3 - Android

Database Inspector Officially Support in Android Studio

Previouslly, Database Inspector start to include in Android Studio 4.1 canary channel, now it is already build in with the latest version of Android Studio Arctic Fox.

Now, Database Inspector is under the App Inspection Tab. You have to choose your connected device, then need to choose package name that you want to inspect for database.

In the left side, show the available tables and need to double click to see table details, and it will be show in the right side.enter image description here.

Option 1

You can use Android-Debug-Database, and you can CRUD of your data from a browser, and then you can see your Preference data from a browser.

Option 2

If you don't want to use from Browser and you have to check other files,need to check your data changes, use a Genymotion Emulator.So you have to root your emulator.Try to Root your emulator, plz see in https://stackoverflow.com/a/44039429/2772552. Let me know if you are not OK.

Solution 4 - Android

Download & Install DB Browser for SQLite

In Android Studio versions >= 3.0:

Open Device File Explorer via:

View > Tool Windows > Device File Explorer

In "Device File Explorer" Go to:

data > data > PACKAGE_NAME > databases

where PACKAGE_NAME is the name of your package (it is com.edgedevstudio.sample in the example below)

Device File Explorer

Right click on the database and select Save As. Save it anywhere you want on your PC.

Open, DB Browser for SQLite & click 'open Database' and open the database. enter image description here

> In the case of the example above, you should locate "todolist" NOT > "todolist-shm" nor "todolist-wal" > >If you do not export the 3 database files (db_name, db_name-shm & db_name-wal, where db_name = name of the database) you will not be able to read the database.

Solution 5 - Android

Personally i use Android Debug Database

> Android Debug Database is a powerful library for debugging databases > and shared preferences in Android applications.

Quick start

Add this to your app's build.gradle

debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'

Just start the application, you will see in the logcat an entry like follows :

D/DebugDB: Open http://192.168.1.104:8080 in your browser

enter image description here


enter image description here


For more information have a look at the github repo

Solution 6 - Android

For easy way, follow these steps:

  1. Download SQLiteBrowser program: Download SQLite for all OS
  2. Click "Device Exploler" where is Right-Bottom corner on Android Studio.
  3. You will see a lot of files. Do not worry! Follow path: data/data/{your app package name}
  4. Right click on "databases" and Save As in your computer.
  5. Open SQLiteBrowser and click "Open Database" than choose file which has same name with your database name.
  6. You can see files and select which has same name with your database table name.
  7. Final step, you can see "Browse Data" option near of "Database Structure" option. When you select it, you can see your data of database.

You can see steps and just follow numbers on below image

You can see steps on image.

Solution 7 - Android

With the latest release of the Android Studio 4.1 Canary, Android Studio provide new tool called Database Inspector.

You can use this Database Inspector tool to view the database file and it's content, you can also edit database content.

enter image description here

If you are using Room Persistence then it also provide facility to run @Query with in the Android Studio. You can see the run button of the left side of the @Query annotation.

enter image description here

If you are using LiveData then it will live reflect database content changes,

enter image description here

Solution 8 - Android

Use Stetho.

Add it to your Android project as a dependency.

Call Stetho.initializeWithDefaults(this) in your Application and view your database using the chrome inspect tool. Enter the following in your chrome URL bar: chrome://inspect.

Presto! You can see your Room database.

Solution 9 - Android

I did this by following steps:

  1. Download the db browser from following link.

https://sqlitebrowser.org/

2)Go to Device File Explorer from IDE & copy three file generated like enter image description here and select all three files : your-db, your-db-shm, your-db-wal

press ctrl+shift+s and paste it to some folder. Done.

  1. finally open the your-db with DbBrowser App.

Solution 10 - Android

With Android Studio 4.1 Canary 6 and higher, you can inspect, query, and modify your app’s databases using the new Database Inspector. For example, you can debug your running app by modifying values in your database and testing those changes on the device.

https://developer.android.com/studio/preview/features#database-inspector

Solution 11 - Android

In latest versions of Android Studio, you can use Database Inspector inside App Inspection Tool Window

enter image description here



Go To App Inspection. Then select the process. Database Inspector will now show the database contents.

enter image description here

Solution 12 - Android

You can see your database table on the DB Browser for SQLite & room DB.

 In android studio 
1. Click on View -> Tool Windows -> Device File Explorer -> data
2. Select your project package name -> database -> select all file and save on desktop

Install **DB browser for SQLITE** 
1. sudo apt-get install sqlitebrowser //write on your terminal for install DB browser
2. install DB browser for sqlite
3. click on Open database and select file where you had saved your data
4. click on Brower Data and see your tables

This is all where i have see my android room database

Solution 13 - Android

You can now view it in Database Inspector in Android Studio

Image below

Database Inspector Tab in Android Studio

Solution 14 - Android

Database Inspector
In the new Android Studio Arctic Fox
Click on the App inspection
Select Database Inspector from the tab
Right Click on the Database name
Click Export as a File
After Download you View the database in DB Browser for SQLite Application
*Note Database Inspector works only if the app deployed on API 26

Solution 15 - Android

I recently tried Sethto By Facebook.

> Stetho is a sophisticated debug bridge for Android applications. When > enabled, developers have access to the Chrome Developer Tools feature > natively part of the Chrome desktop browser

You just need to include it's gradle dependency and call in MainApp. That's it. You get access to all the tools in chrome window by using chrome://inspect/ including your sqlite database.

Following is a screenshot where inspected by Room Database on Emulator. I only tried in emulator so far.

enter image description here

Solution 16 - Android

after getting your DB (3 files) from Device File Explorar as comments said above

I really recommend easy program like using "DB Browser for SQLite" https://sqlitebrowser.org/

Solution 17 - Android

Google official: Nowadays there's a super simple way to view your Room DB straight from Android Studio. So simple you will laugh =) Check this out: https://developer.android.com/studio/inspect/database

Solution 18 - Android

Best and easy to view, edit, add & delete your roomdatabase in debug mode in android studio.

> Implement dependency in build.gradle

debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'

> Copy paste below code in your activity

public static void showDebugDBAddressLog() {
    if (BuildConfig.DEBUG) {
        try {
            Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
            Method getAddressLog = debugDB.getMethod("getAddressLog");
            Object value = getAddressLog.invoke(null);
            Log.d("link", "showDebugDBAddressLogToast: "+(String) value);
        } catch (Exception ignore) {

        }
    }
}

> Call Activity in oncreate.

showDebugDBAddressLog();

> Add permission in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

> Run The app in dubug mode

> Search in logcat

link

> You see the link in logcat

showDebugDBAddressLog: Open http://192.168.1.100:8080 in your browser

> Open link "http://192.168.1.100:8080" in your browser.

Boom you see your all database. Thank You

Solution 19 - Android

Follow the below documentation from Android

https://developer.android.com/studio/inspect/database

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpiralDevView Question on Stackoverflow
Solution 1 - AndroidkrekerView Answer on Stackoverflow
Solution 2 - AndroidAvinash JadaunView Answer on Stackoverflow
Solution 3 - AndroidHtoo Aung HlaingView Answer on Stackoverflow
Solution 4 - AndroidLekeOpeView Answer on Stackoverflow
Solution 5 - AndroidchebabyView Answer on Stackoverflow
Solution 6 - AndroidNamelessView Answer on Stackoverflow
Solution 7 - AndroidChandan SharmaView Answer on Stackoverflow
Solution 8 - AndroidIzakView Answer on Stackoverflow
Solution 9 - Android100RaBHView Answer on Stackoverflow
Solution 10 - AndroidJeffrey LiuView Answer on Stackoverflow
Solution 11 - AndroidAll Іѕ VаиітyView Answer on Stackoverflow
Solution 12 - AndroidHandyPawanView Answer on Stackoverflow
Solution 13 - AndroidJayesh NView Answer on Stackoverflow
Solution 14 - AndroidSohail AhmadView Answer on Stackoverflow
Solution 15 - AndroidAjjiView Answer on Stackoverflow
Solution 16 - AndroidAmr263View Answer on Stackoverflow
Solution 17 - AndroidBarakudaView Answer on Stackoverflow
Solution 18 - AndroidKumar SantanuView Answer on Stackoverflow
Solution 19 - Androidarango_86View Answer on Stackoverflow