129

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

3
  • 8
    easier way compared to which way? Jun 8, 2017 at 7:35
  • 1
    compared to old approaches like using DDMS or via adb shell. DDMS freezes my computer and using adb requires a lot of work. I think there must be easier way as it was released by Google recently
    – SpiralDev
    Jun 8, 2017 at 7:39
  • 12
    Not in android studio, but this github.com/facebook/stetho is the best Android Debug bridge developed by facebook, from which you can see your app database, even sharedpreferences, etc.
    – Moinkhan
    Jun 8, 2017 at 8:45

20 Answers 20

104

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/
9
  • 2
    operation not permitted
    – Jono
    Jan 11, 2019 at 13:22
  • 2
    @jonney This method will only work on rooted device or emulator. Mar 13, 2019 at 10:32
  • 2
    This should also work on a non-rooted phone with debuggable app installed, except Samsung devices
    – Gaket
    Jun 10, 2019 at 16:56
  • 1
    This should be the accepted answer - easiest way to get the DB without having to download software or root the device. Oct 8, 2019 at 16:09
  • 1
    @JakubJabłoński launch your app on emulator, than open Device File Explorer in Android Studio
    – k4dima
    Nov 21, 2019 at 14:54
90

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.

6
  • Able to see database file but unable to view created tables in database. I have tried both methods
    – Ravikiran
    May 15, 2018 at 1:02
  • 9
    Finally I found the solution after a day work. Export "userdatabase","userdatabase-shm" and "userdatabase-wal" files from emulator and open "userdatabase" file in sqlite viewer
    – Ravikiran
    May 15, 2018 at 1:52
  • if .db is in the internal dir, you are not allowed to see there, manually copy .db file to external storage dir and it will work for u May 16, 2018 at 13:01
  • I had a problem with method 1 where it was causing read/write problems with other async tasks. Caused the app to freeze.
    – Jeffrey
    Feb 20, 2019 at 2:37
  • is @chandan-sharma answered this answer need an update : 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.
    – golkarm
    Mar 10, 2021 at 8:41
85

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

5
  • How can I find out where the "/data/data/..." path is on my filesystem? Sep 14, 2018 at 12:43
  • The author of this answer actually shows where ``Device File Explorer` lives, which saves some time for newbies; hence +1 Sep 29, 2018 at 15:47
  • @AwaisHussain : use context.getDatabasePath("your-db-name.db")
    – gMale
    Nov 28, 2018 at 8:14
  • Press shift twice to search everywhere and type in Device File Explorer if its been removed from the bottom right hand corner in your android studio.
    – COYG
    Apr 26, 2019 at 15:25
  • It's important to copy ALL 3 files. Copying only the one with the database name, will result in not synced data, even if the used SQL manager OPEN IT CORRECTLY with tables and create its own shm and wal.
    – Jumpa
    Aug 6, 2020 at 9:42
50

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.

1
  • This is what I was looking for.. Exactly what required! Thanks @EdgeDev
    – Kannan_SJD
    Nov 5, 2019 at 8:50
20

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

3
  • 1
    This is the best way as no need to root the device
    – Sunil
    May 13, 2020 at 17:32
  • 1
    Wow! Amazing stuff!! Thanks dude!!
    – Barakuda
    May 22, 2020 at 12:11
  • 1
    Amazing. This is the best third party tool I ever used with Android. Saved a lot of time. Great respect to the developer
    – Sojan P R
    Jan 12, 2021 at 1:30
16

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.

14

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

7

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.

4

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

1
  • 1
    in 2021, with current Android Studio, this should be the only accepted answer. Aug 1, 2021 at 11:59
3

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.

3) finally open the your-db with DbBrowser App.

1
  • thanks, have to select all three files: *-db, *-db-shm, *-db-wal
    – xyz
    Apr 23, 2019 at 9:45
2

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

1
  • This should be the official answer. Aug 27, 2020 at 22:29
1
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
1

You can now view it in Database Inspector in Android Studio

Image below

Database Inspector Tab in Android Studio

1

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

1

In android atudio you'll find a tab in the bottom "App Inspector" There is a seperate tab for Database inspection. From there you can see all the databases in the device

0

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

0

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/

0

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

0

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

0

Follow the below documentation from Android

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.