View contents of database file in Android Studio
Asked Answered
W

31

301

I have been using Android Studio to develop my app since it's was released.

Everything works nice until recently, I have to debug together with checking the database file. Since I don't know how to see the database directly, When I debugged to generate the database file, I have to export the database file from my phone to the PC.

In order to do this, I have to open DDMS > File Explorer. Once I open the DDMS, I have to reconnect the USB, and I lose my debug thread. After checking the database file, I have to close the DDMS and reconnect the USB again to get back to the debug mode.

It's just too complicated. Does anyone have a better way to do this in Android Studio (I know it's easier in Eclipse) ?

Whisenant answered 8/7, 2013 at 14:54 Comment(1)
Now this feature is available Android Studio itself: developer.android.com/studio/inspect/databaseMaynord
W
28

Finally, i found a simplest solution which do not need to open the DDMS.

Actually, the solution is based on what @Distwo mentioned, but it don't have to be that complicated.

First, remember the path of your database file in the device, it should aways the same. For example mine is:/data/data/com.XXX.module/databases/com.XXX.module.database

Second, execute this command which pulls your database file onto you PC

 adb pull /data/data/com.XXX.module/databases/com.XXX.module.database /Users/somePathOnYourPC/

What you need to do is just copy and store this command, then you can use it again and again.

Third, if you got Permission Denied or something like that, just run adb root before the previous command.

Whisenant answered 13/12, 2013 at 4:32 Comment(5)
Running adb root does not work on my phone. It prints out adbd cannot run as root in production builds. After running adb root, though, the pull command just freezes and I need to stop it manually.Cascabel
@Daniela try run-as your.package.name this should "log you in" as the user belonging to your appSemifluid
Use above command to copy the .db file to your Desktop, install SQLiteManager browser plugin in Firefox and start browsing. 2 minute job!Executive
that root command was for emulator, you can't just run this command and root your 'phone'.Dishearten
everything is done, got the database.db. file BUT that database.db file doesn't contains any tablesRespectable
P
339

Viewing databases from Android Studio:

Option 1:

  1. Download and install SQLiteBrowser.

  2. Copy the database from the device to your PC:

    • Android Studio versions < 3.0:

      • Open DDMS via Tools > Android > Android Device Monitor

      • Click on your device on the left.
        You should see your application: enter image description here

      • Go to File Explorer (one of the tabs on the right), go to /data/data/databases enter image description here

      • Select the database by just clicking on it.

      • Go to the top right corner of the Android Device Monitor window. Click on the 'pull a file from the device' button: enter image description here

      • A window will open asking you where you want to save your database file. Save it anywhere you want on your PC.

    • Android Studio versions >= 3.0:

      • Open Device File Explorer via View > Tool Windows > Device File Explorer

      • Go to data > data > PACKAGE_NAME > database, where PACKAGE_NAME is the name of your package (it is com.Movie in the example above)

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

  3. Now, open the SQLiteBrowser you installed. Click on 'open database', navigate to the location you saved the database file, and open. You can now view the contents of your database.


Option 2:

Go to this Github repository and follow the instructions in the readme to be able to view your database on your device. What you get is something like this:

enter image description here

That's it. It goes without saying however that you should undo all these steps before publishing your app.

Penetration answered 5/2, 2015 at 8:18 Comment(11)
thats for me the correct answer because the hint with the sqlitebrowser tool, it's awesome. Thank'sUnlearn
/data doesn't expand in file explorer of Device Monitor, i guess its inaccessible since listing entries of /data or /data/data directory requires superUser access. I am still able to access my database files through adb shell with su privileges. Have any idea how to get su access in file manager?Meadowsweet
I don't have the slightest idea.It's frustrating.Penetration
@ZekeDran, yes the method only shows data from an emulator not your device.I have added steps to view the database on your device though.Check the editPenetration
It works, but the emulator has to be running not more than API 23. If you use API 25, then there are no contents in the file explorerOvercapitalize
The database manager from your Github link is working for me! It also has the opportunity to test queries!Sverdlovsk
In my case with API 25 I did not see my application listed. Instead I browsed the com.android.phone node and rest of instructions worked fine.Khz
Good answer, but instead of checking device monitor, look into "Device File Explorer" in android StudioExotoxin
In my case, a pop up is been shown saying, "disable the following debug session". If i click on yes, then in fileexplorer i am unable to see the app.Kendra
this really helped me to find my wayKelm
Flutter devs who ran into ADB:Android Debug Bridge not found issue, look here.. github.com/flutter/flutter/issues/55557#issuecomment-643488225Royalty
K
207

Connect to Sqlite3 via ADB Shell

I haven't found any way to do that in Android Studio, but I access the db with a remote shell instead of pulling the file each time.

Find all info here: http://developer.android.com/tools/help/adb.html#sqlite

1- Go to your platform-tools folder in a command prompt

2- Enter the command adb devices to get the list of your devices

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb devices
List of devices attached
emulator-xxxx   device

3- Connect a shell to your device:

C:\Android\adt-bundle-windows-x86_64\sdk\platform-tools>adb -s emulator-xxxx shell

4- Navigate to the folder containing your db file:

cd data/data/<your-package-name>/databases/

5- run sqlite3 to connect to your db:

sqlite3 <your-db-name>.db

6- run sqlite3 commands that you like eg:

Select * from table1 where ...;

Note: Find more commands to run below.

SQLite cheatsheet

There are a few steps to see the tables in an SQLite database:

  1. List the tables in your database:

    .tables
    
  2. List how the table looks:

    .schema tablename
    
  3. Print the entire table:

    SELECT * FROM tablename;
    
  4. List all of the available SQLite prompt commands:

    .help
    
Kittie answered 16/8, 2013 at 19:7 Comment(12)
i get permission denied at step 4, what do you think?Butene
You may have to root your avd, and/or start adb as root at step 3 'root adb -s emulator-xxxx shell'Kittie
You don't need the .db extension. I used it and it ended up creating another (blank) file. So I had both some_database and some_database.dbEscadrille
step 5: sqlite3 not found. Why?Girondist
Because you need to install in in order to useVindictive
I have sqlite3 in the sdk/platform-tools folder but still I get sqlite3 not found error.Find
Same here, I to got sqlite3 in the platform-tools folder, but I cannot find it.Gaucho
@JayeshPrakash You need to install sqlite in the device see this linkCyclotron
I personnaly got Permission denied when trying to access the databases folder, running run-as your.package.name did the trick.Cuenca
nice solution. Before step 4 use su to login as root for access data directory.Market
This is great, I was trying for emulator and permission denied kept coming. Please try these two command to get access to your application data on emulator 1) add shell 2) run-as com.test.applicationConroy
for ubuntu how can i access db?Comradery
D
85

I'm actually very surprised that no one has given this solution:

Take a look at Stetho.

I've used Stetho on several occasions for different purposes (one of them being database inspection). On the actual website, they also talk about features for network inspection and looking through the view hierarchy.

It only requires a little setup: 1 gradle dependency addition (which you can comment out for production builds), a few lines of code to instantiate Stetho, and a Chrome browser (because it uses Chrome devtools for everything).

Update: You can now use Stetho to view Realm files (if you're using Realm instead of an SQLite DB): https://github.com/uPhyca/stetho-realm

Update #2: You can now use Stetho to view Couchbase documents: https://github.com/RobotPajamas/Stetho-Couchbase

Update #3: Facebook is focusing efforts on adding all Stetho features into its new tool, Flipper. Flipper already has many of the features that Stetho has. So, now may be a good time to make the switch. https://fbflipper.com/docs/stetho.html

Dolt answered 24/11, 2015 at 4:1 Comment(4)
Thank a lot. To be more simple, 1.compile 'com.facebook.stetho:stetho:1.3.1' and 2. add this code Stetho.initializeWithDefaults(this); and 3. chrome://inspect/#devicesSoukup
Very simple, you can see data from the database without 3rd party tools, inside chrome browser.Forevermore
Don't forget Stetho.initializeWithDefaults(this); should be in the Application class.Sciurine
Great tool. Your app will be listed on the #devices page if you've done the setup correctly. Click Inspect and then go to Resources > Web SQL > [db_name] and you can write your sqlite statements.Bioastronautics
T
74

Simplest method when not using an emulator

$ adb shell
$ run-as your.package.name
$ chmod 777 databases
$ chmod 777 databases/database_name
$ exit
$ cp /data/data/your.package.name/databases/database_name /sdcard
$ run-as your.package.name # Optional
$ chmod 660 databases/database_name # Optional
$ chmod 660 databases # Optional
$ exit # Optional
$ exit
$ adb pull /sdcard/database_name

Caveats:

I haven't tested this in a while. It may not work on API>=25. If the cp command isn't working for you try one of the following instead:

# Pick a writeable directory <dir> other than /sdcard
$ cp /data/data/your.package.name/databases/database_name <dir>

# Exit and pull from the terminal on your PC
$ exit
$ adb pull /data/data/your.package.name/databases/database_name

Explanation:

The first block configures the permissions of your database to be readable. This leverages run-as which allows you to impersonate your package's user to make the change.

$ adb shell
$ run-as your.package.name
$ chmod 777 databases
$ chmod 777 databases/database_name
$ exit # Closes the shell started with run-as

Next we copy the database to a world readable/writeable directory. This allows the adb pull user access.

$ cp /data/data/your.package.name/databases/database_name /sdcard

Then, replace the existing read/write privileges. This is important for the security of your app, however the privileges will be replaced on the next install.

$ run-as your.package.name
$ chmod 660 databases/database_name 
$ chmod 660 databases
$ exit # Exit the shell started with run-as

Finally, copy the database to the local disk.

$ exit # Exits shell on the mobile device (from adb shell) 
$ adb pull /sdcard/database_name
Theomorphic answered 15/5, 2015 at 17:51 Comment(6)
I get problems with the 2nd command: run-as. I'm getting 'com.mycompany.myappname' is unknown. And yes, I'm positive that I'm using the correct package name!Phallus
@PhuLai have you tried a different device? What device is failing?Theomorphic
I tried with Nexus 6P, API 25. I think this method will not work on new Android versions.Marley
chmod 660 databases/database_name should be before chmod 660 databasesTarpon
@PhuLai - I got this too and then I tried skipping the cp command and just doing a pull from outside (after changing permissions) and it worked (adb pull data/data/package.name/databases/db_name.db)Tarpon
Maybe /sdcard is no longer writable.Theomorphic
C
69

In Android Studio 3 and above You Can See a "Device File Explorer" Section in Right-Bottom Side of Android Studio.

Open it, Then You Can See The File Tree, You Can Find an Application Databases In this Path:

/data/data/{package_name}/databases/

enter image description here

Rightclick the db file and Save As... (then save to your desktop).

Then using the SQLite sqlitebrowser.org (Download and install first), click Open Database, select the saved *.db file, and select Browse Data tab and select the table to see its contents. enter image description here

Circumvent answered 28/12, 2017 at 6:48 Comment(5)
When I double click on the DB file for my app, it shows all unreadable characters. What SQLite reader do you use to look at the DB contents?Bulbous
I recommend sqlitebrowser.org free ,open source and available for all platforms.Circumvent
my database.db file doesn't contains any tables.Respectable
Folder is empty. Error : run-as: Could not set capabilities: Operation not permitted. Samsung device: #37414167Wier
Note that you have to download all three files belonging to the database from the databases folder. Then you can open the main file (without suffixes) with sqlitebrowser (which, when not opened as read-only, will actually merge them into one). (This holds at least for a Room 2.4.3 database.)Gabon
W
28

Finally, i found a simplest solution which do not need to open the DDMS.

Actually, the solution is based on what @Distwo mentioned, but it don't have to be that complicated.

First, remember the path of your database file in the device, it should aways the same. For example mine is:/data/data/com.XXX.module/databases/com.XXX.module.database

Second, execute this command which pulls your database file onto you PC

 adb pull /data/data/com.XXX.module/databases/com.XXX.module.database /Users/somePathOnYourPC/

What you need to do is just copy and store this command, then you can use it again and again.

Third, if you got Permission Denied or something like that, just run adb root before the previous command.

Whisenant answered 13/12, 2013 at 4:32 Comment(5)
Running adb root does not work on my phone. It prints out adbd cannot run as root in production builds. After running adb root, though, the pull command just freezes and I need to stop it manually.Cascabel
@Daniela try run-as your.package.name this should "log you in" as the user belonging to your appSemifluid
Use above command to copy the .db file to your Desktop, install SQLiteManager browser plugin in Firefox and start browsing. 2 minute job!Executive
that root command was for emulator, you can't just run this command and root your 'phone'.Dishearten
everything is done, got the database.db. file BUT that database.db file doesn't contains any tablesRespectable
B
20

Simple and easy way to see database content within Android studio.

#For Android Studio 4.1 Canary 6 and higher

You can use a very simple Android Studio's feature Database Inspector. Where 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 in real-time without leaving Android Studio.

To get started, deploy your app to a device running API level 26 or higher and select View > Tool Windows > Database Inspector from the menu bar.

#For Android Studio 4.0 and lesser

First, install Database Navigator plugin in Android Studio

enter image description here

Second, Restart Android Studio

Third, save the database into the default location like: (C:\Users\User Name\Documents\AndroidStudio\DeviceExplorer\emulator or device\data\data\package name\databases)

enter image description here

Fourth, Connect saved dbname_db file in Database Navigator

enter image description here enter image description here

Give same DB file path that is used in step Third

i.e (C:\Users\User Name\Documents\AndroidStudio\DeviceExplorer\emulator or device\data\data\package name\databases\package naem\dbname_db)

Finally, just test DB connection and open console and do whatever you want to do.

enter image description here

If you want to refresh DB just repeat step Second and just save it or refresh.

HAPPY CODING!!!!!

Briticism answered 15/10, 2019 at 6:43 Comment(8)
This solution need a lot of efforts for your every day work. And on each change in the database you need to reload sql file - seem a bit complicated. I prefer to use some plugins which give ability to view database on the local serverForegoing
Yes, you are right, till there is no realtime data update in Database Navigator, I hope it will update it's plugins soon.Briticism
Exactly, it would be a great featureForegoing
Yes, until now this one is the best way for me if we need to query data, add, edit and deleteBriticism
Do I need always to do the save to refresh the database? is there an easier way like in mysql all I need is to hit the refresh button.Darwen
Till now it is the only process to refresh. Hope will address in the future update of Plugin. If you like to see DB data outside the android studio can use a library like https://mcmap.net/q/101749/-view-sqlite-database-on-device-in-android-studioBriticism
@ンドリューライアンア If you are using android studio 4.1 Canary 6 and higher here is simple way you can go through it Database Inspector developer.android.com/studio/preview/…Briticism
Couldn't even get it to work in the end after all the trouble of setting it up. All I wanted was to just check the database, this seems like a very excessive solution to what the OP was asking which is to simply view the contents of a database.Zondra
D
20

The easiest way is to use Android Debug Database library (8.3k stars on GitHub).

Android-Debug-Database

Advantages:

  • Fast implementation
  • See all the databases and shared preferences
  • Directly edit, delete, create the database values
  • Run any SQLite query on the given database
  • Search in your data
  • Download database
  • Adding custom database files
  • No need to root device

How to use:

  1. Add debugImplementation 'com.amitshekhar.android:debug-db:1.0.6' to build.gradle (module);
  2. Launch app;
  3. Find the debugging link in logs (in LogCat) (i.e. D/DebugDB: Open http://192.168.232.2:8080 in your browser, the link will be different) and open it in the browser;
  4. Enjoy the powerful debugging tool!

Important:

  • Unfortunately doesn't work with emulators
  • If you are using it over USB, run adb forward tcp:8080 tcp:8080
  • Your Android phone and laptop should be connected to the same Network (Wifi or LAN)

For more information go to the library page on GitHub.

Desirous answered 2/12, 2019 at 9:54 Comment(6)
This is the best and less painful process ! Thank you DanielPellikka
fyi for some who may be here, I couldn't get this to work on react native android so farRipieno
Best solution by far!Davilman
According to the github page, it does work with emulators. I haven't tested this yet, but will edit this comment accordingly.Tallow
UPDATE: Hmm. It won't compile with my code - something to do with inconsistent versions of compatibility libraries which I can't be bothered to figure out.Tallow
UPDATE: Ah, apparently Android Studio 'app inspection' tool does the job fine now.Tallow
B
16

Try this android studio plugin SQLScout. you can see and edit your app database realtime.

SQLScout

Edit: Remember it's a paid plugin, but have 24h trial and suitable for headache time.

Branching answered 10/10, 2016 at 15:51 Comment(4)
It's paid product, you forgot to mention.Yuyuan
not really, it has 24 hours trial, I planned my future as a developer for more than 24 hours.Yuyuan
Sadly, It is not free.Creamy
Ther trial time is only 36 hours.Purusha
B
12

After going through all the solutions i will suggest

Use Stethos
Lets see how Simple it is

Add following dependencies in build.gradle file

implement 'com.facebook.stetho:stetho:1.5.0'
implement 'com.facebook.stetho:stetho-js-rhino:1.4.2'

Then go to you mainActivity onCreate method add following line

Stetho.initializeWithDefaults(this);

this would require you to

import com.facebook.stetho.Stetho;

now while running app from android studio , Open Chrome and in address bar type
chrome://inspect/

in the resources tab >web SQL check the the database and table play with it in real time easily

Update: Stethos is broken in recent versions of Chrome. If having trouble, try Edge dev tools instead edge://inspect/#devices - See: https://mcmap.net/q/101750/-chrome-devtools-broken-stetho-unusable

Bonnet answered 3/7, 2018 at 14:18 Comment(1)
Room is just orm, nothing changes in terms of sql it works same wayBonnet
P
11

Even though this is pretty old question but I think it's still relevant today. With the latest version of android studio I found a way to see it [ I am not sure if it was available in the previous versions. ]

Here is how you can see the data in your database :

steps :

  1. Go to View > Tool Windows > Device File Explorer

  2. Then the folder data > data and you will see applications lists.

  3. There scroll down a little bit and see the package [ your package for application ].

  4. After finding your package, see databases folder and select file, right click it and save [ download ]

  5. As you can't see the data directly, there is a tool, DB Browser for SQLite, go website https://sqlitebrowser.org/

  6. Open Db browser and click open database and choose the database table you downloaded and it will show you the data.

NEW EDIT

Now (the time you're reading this post), it's even easier because Android studio already comes with database inspector (just near to bottom right corner).

Click on that and you will see the database. But, make sure that minimun API level is 26, if not change it through build.gradle file as minSdkVersion 26

Papistry answered 20/8, 2020 at 11:43 Comment(0)
I
8

New Database Inspector introduced in Android 4.1 Canary 5 Preview where you can now Inspect, query, modify, and debug SQLite databases in your running app directly from the IDE - https://developer.android.com/studio/preview/features?linkId=86173020#database-inspector

Supports database live query as well - https://developer.android.com/studio/preview/features?linkId=86173020#query

enter image description here

Inveracity answered 10/4, 2020 at 9:52 Comment(1)
I have already posted this answer so it's just a duplicate answer and no need to post a link to this answer at the top for promotion.Cicero
A
6

To know where sqlite database stored created by you in android studio, you need to follow simple steps:

1.Run your application
2.Go to Tools--->Android---->Device Monitor
3.Find your application name in left panel
4.Then click on File Explorer tab
5.Select data folder
6.Select data folder again and find your app or module name
7.Click on your  database name
8.On right-top window you have an option to pull file from device.
9.Click it and save it on your PC
10.Use FireFox Sqlite manager to attach it to your project.

For more information this link will be useful. http://www.c-sharpcorner.com/UploadFile/e14021/know-where-database-is-stored-in-android-studio/

To view your data present in db file you need to download sqlite browser or add plugin of the same in any browser so you need to open file in browser and view your data.

Download browser from http://sqlitebrowser.org/

Here is screenshot showing browser containing register database

Thanks,

Axiology answered 23/12, 2014 at 11:52 Comment(0)
C
6

The simplest way is to Attach your device and run Android Studio Then From Tool Bar:

  1. View --> Tools Window --> Device File Explorer
  2. Go into data/data and find your package
  3. find the DB file you want to explore and download it
  4. I recommend on this online tool: https://sqliteonline.com/ to explore the db file

Another way is using Stetho library:

  1. Add Stello dependency to your build.gradle:

    compile 'com.facebook.stetho:stetho:1.5.0'

  2. Put Following line on your onCreate() of your Application class or main Activity:

    Stetho.initializeWithDefaults(this);

  3. Connect your device, run the app and Enter the following site on Chrome:

    chrome://inspect/#devices

and that is it. you can now explore your tables.

Note: it is recommended to remove the dependency before moving to production.

Carolus answered 7/8, 2018 at 12:3 Comment(0)
C
6

With the release of Android Studio 4.1 Canary and Dev preview , you can use a new tool called

Database Inspector

DB inspector

Install AS 4.1+, run the app, open database inspector, now you can view your database files on the left side of the database inspector panel then select the table to view the content.

Live Queries

Either you can run you queries using Run SQL option or if you are using Room then open database inspector and run the app then, you can run the DAO queries in your interface by clicking on the run button on left of @Query annotation.

live queries

Cicero answered 9/4, 2020 at 19:39 Comment(0)
A
5

If you want to browse your databases FROM WITHIN ANDROID STUDIO, here's what I'm using:

Go to Files / Settings / Plugins and look for this:

enter image description here

... After having restarted Android Studio you can pick your downloaded database file like this: enter image description here

... Click the "Open SQL Console" icon, and you end up with this nice view of your database inside Android Studio: ![enter image description here

Allonym answered 15/5, 2019 at 8:55 Comment(1)
So I have to copy db from emulator all the time ?Vellum
P
2

This might not be the answer you're looking for, but I don't have a better way for downloading DB from phone. What I will suggest is make sure you're using this mini-DDMS. It will be super hidden though if you don't click the very small camoflage box at the very bottom left of program. (tried to hover over it otherwise you might miss it.)

Also the drop down that says no filters (top right). It literally has a ton of different ways you can monitor different process/apps by PPID, name, and a lot more. I've always used this to monitor phone, but keep in mind I'm not doing the type of dev work that needs to be 120% positive the database isn't doing something out of the ordinary.

Hope it helps

enter image description here

Platinize answered 13/8, 2013 at 11:18 Comment(0)
G
2

I've put together a unix command-line automation of this process and put the code here:

https://github.com/elliptic1/Android-Sqlite3-Monitor

It's a shell script that takes the package name and database name as parameters, downloads the database file from the attached Android device, and runs the custom script against the downloaded file. Then, with a unix tool like 'watch', you can have a terminal window open with a periodically updating view of your database script output.

Godewyn answered 24/11, 2015 at 3:51 Comment(0)
R
2

This is a VERY old question and my answer is similar to some answers above but done MUCH faster. The script below is for Mac but I'm sure someone can modify it for Windows.

1) Open Script Editor on your Mac (you can just search for Script Editor in Spotlight)
2) Copy and paste the text below and modify it with your SDK path, package name, etc. (see below)
3) Save the script!!

Thats's it! Just press the play button on top to get the updated database file, which will be on your desktop.

replace the following things in the script below:

path_to_my_sdk ==>> put full path to your sdk
my_package_name ==>> package name of your application
myDbName.db ==>> file name of your database

set getLocalDb to "path_to_my_sdk/platform-tools/adb shell run-as my_package_name chmod 777 databases && path_to_my_sdk/platform-tools/adb shell run-as my_package_name chmod 777 databases/myDbName.db && path_to_my_sdk/platform-tools/adb shell run-as my_package_name cp databases/myDbName.db /sdcard/myDbName.db && path_to_my_sdk/platform-tools/adb pull /sdcard/myDbName.db /Users/User/Desktop/myDbName.db"
do shell script getLocalDb

Hope this helps someone.

Raising answered 27/12, 2016 at 19:35 Comment(1)
It worked for me. Except you have to change the 'User' to Your MacBook User name in the output directory /Users/User/Desktop/myDbName.dbWindbroken
G
2

I know the question is rather old but I believe this issue is still present.

Viewing databases from your browser

I created a development tool that you can integrate as a lib into your android app project. The tool opens a server socket in your app to communicate via web browser. You can browse through your whole database and download the database file directly through the browser.

enter image description here

Integration can be done via jitpack.io:

project build.gradle:

//...
allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}
//...

app build.gradle:

//...
dependencies {
    //...
    debugCompile 'com.github.sanidgmbh:debugghost:v1.1'
    //...
}
//...

Setup Application class

In order to only compile DebugGhostLib in certain build-types or product-flavours we need an abstract Application class which will be derived in the special flavours. Put the following class in your main folder (under java > your.app.package):

public class AbstractDebugGhostExampleApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // Do your general application stuff
    }
}

Now, for your release build type (or product flavour), you add the following Application class to your release (or product-flavour) folder (also under java > your.app.package):

public class MyApp extends AbstractDebugGhostExampleApplication {
    @Override
    public void onCreate() {
        super.onCreate();
    }
}

This is the application class that will not reference DebugGhostLib.

Also tell your AndroidManifest.xml that you're using your own application class. This will be done in your main folder:

<manifest package="demo.app.android.sanid.com.debugghostexample" xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- permissions go here -->
    <application android:name=".MyApp"> <!-- register your own application class -->
        <!-- your activities go here -->
    </application>
</manifest>

Now, for your debug build type (or product flavour), you add the following Application class to your debug (or product-flavour) folder (also under java > your.app.package):

public class MyApp extends AbstractDebugGhostExampleApplication {
    private DebugGhostBridge mDebugGhostBridge;

    @Override
    public void onCreate() {
        super.onCreate();

        mDebugGhostBridge = new DebugGhostBridge(this, MyDatabaseHelper.DATABASE_NAME, MyDatabaseHelper.DATABASE_VERSION);
        mDebugGhostBridge.startDebugGhost();
    }
}

You can get the tool here.

Gipsy answered 30/6, 2017 at 8:58 Comment(1)
this is a good tool specifically after Stetho stopped working in newer chrome,Precessional
E
2

I had to pull the database from phone to PC. Now I use this very well made and free app which has a lot of features. It works on API 4.1+with a Rooted device.
Let me know if you find how to make it work without root.

Screenshot SqlitePrime

https://play.google.com/store/apps/details?id=com.lastempirestudio.sqliteprime

Eckstein answered 6/10, 2017 at 18:10 Comment(0)
H
2

Open the Device File Explore Terminal at the Bottom of the Android Studio.

Open The folder named Data , then inside Data again open the Folder Data .

Open the folder data

Scroll Down the list of folders and find the folder with your.package.name. Open folder your.package.name > Database. You get your.databaseName. Right Click your.databaseName and Save as to C:/your/Computer/Directory.

Go to C:/your/Computer/Directory open your.databaseName with DB SQLite

enter image description here

Hame answered 5/8, 2018 at 19:47 Comment(0)
C
2

For Android Studio 3.X

  1. View -> Tool Windows -> Device File Explorer
  2. In The File Explorer data->data->com.(yourapplication package)->databases
  3. Right Click On The Database And Save on your local machine. To open, the file you can use SQLite Studio by just dragging the Database file on it.

Here is the link to SQLite Studio : https://sqlitestudio.pl/index.rvt?act=download

Corselet answered 6/8, 2018 at 6:40 Comment(0)
D
2

Finally, Android Studio supports this functionality with database inspector tab. You can apply view/update/query operations easily. It's not in stable channel for now but you can try out with the Android Studio 4.1 Canary 5 and higher.

You can see what the database inspector looks like here

And you can download appropriate version here

Dachi answered 13/4, 2020 at 12:18 Comment(0)
E
2

Use android sqlite like the server side database

Folow these steps listed below:

  1. Find the Database tool window and click it like below image

enter image description here

  1. Click the plus icon and select Android SQLite like below image

enter image description here

  1. Connect your android device to your computer

  2. Select the package you care and select the database like below image enter image description here

  3. Before all these steps above you must esure that you have the right permission to access the file : /data/data//database/databasefile.db

After all these steps you will see the database content like below :

enter image description here

enter image description here

Last important thing is

You must click the update icon every time where database data has been updated.

enter image description here

Hope this is work for you! Thank you !

Erdmann answered 28/5, 2020 at 1:40 Comment(0)
S
2

Android Studio has a Database Inspector bundled since version 4.1.

But it has one limitation:

The Database Inspector only works with the SQLite library included in the Android operating system on API level 26 and higher. It doesn't work with other SQLite libraries that you bundle with your app.

Sewer answered 24/1, 2021 at 9:56 Comment(0)
H
2

I wonder why this solution was not mentioned here!

...In Android Studio 4.1 and higher...

1.Run your app on an emulator or connected device running API level 26 or higher.

2.Select View > Tool Windows > Database Inspector from the menu bar.

3.Select the running app process from the dropdown menu.

4.The databases in the currently running app appear in the Databases pane. Expand the node for the database that you want to inspect.

enter image description here

Harquebusier answered 13/5, 2021 at 19:19 Comment(1)
I updated Android studio, they changed it to App inspector. Damn, spend almost half an hour figuring out where is Database Inspector. lol. I should also follow release notes.Strafford
S
2

In Arctic fox Studio, its located in the bottom toolbar as "App Inspection"

app inspection

Stank answered 25/1, 2022 at 14:0 Comment(0)
L
0

I'm using windows 7, my device is a emulated android device API 23. I suppose it is the same for any real device as long as it is rooted and the API is not above 23

Go to Tools -> Android -> Android Device Monitor. Go to File Explorer. In my case, it is in data/data//app_webview/databases/file_0/1

I have to manually add .db at the end of the file named "1"

Laroy answered 23/5, 2017 at 3:33 Comment(0)
P
0

Its a combination from other answers with a plus

  1. Install DB Browser for SQLite
  2. Get the exact location from Device File Explorer for MyBase.db something like "/data/data/com.whatever.myapp/databases/MyBase.db"
  3. Set the project window from Android to Project - so you can see the files (build.gradle, gradle.properties,...etc)
  4. In Project window right click and chose Open in Terminal
  5. In terminal you are now in the root director of your application from the hardisk so execute: adb pull /data/data/com.whatever.myapp/databases/MyBase.db
  6. Now on the Project window of you Android Studio you have a file "MyBase.db"
  7. Double click your db file from Project and you can now browse/edit your databases in DB Browser
  8. When you are ready just do Write Changes in DB Browser so databases are saved on hardisk
  9. In terminal with the command: adb push MyBase.db /data/data/com.whatever.myapp/databases/MyBase.db you just send from the Hardisk to device the edited database.
Prescription answered 17/3, 2019 at 21:54 Comment(0)
P
0

Follow the above steps to open the database folder of your app in Android Device explorer and in there you can see six files, The first three is named as android and the last three is named as your database name. You only have to work with the last three files, save these three files at your preferred location. You can save these files by right-clicking to the file and click save as button (like I have my database named as room_database and so three files are named as room_database, room_database-shm, and room_database-wal. Rename the corresponding file as follows:-

1) room_database to room_database.db 2) room_database-shm to room_database.db-shm 3) room_database-wal to room_database.db-wal

Now open the 1st file in any SQLite browser and all the three files will be populated in the browser.

Phenol answered 15/12, 2019 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.