View contents of database file in Android Studio
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.
View contents of database created with Room Persistence Library
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..
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.
How can I view the contents of my AVD database?
I was able to figure it out. Here's what I did:
All three files just needed to be renamed to .db, .db-shm, and .db-wal respectively. DB Browser was able to open the files. Sqliteman still won't work. It's probably too old.
View SQLite database on device in Android Studio
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:
List the tables in your database:
.tables
List how the table looks:
.schema tablename
Print the entire table:
SELECT * FROM tablename;
List all of the available SQLite prompt commands:
.help
Source : This SO answer..
View contents of database file in Android Studio
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.
Where I can Find Android database file in my app?
Here is the path: /data/data/YOUR_PACKAGE/databases/
P.S. May be that link can help:
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
How to get the live view of inserted data in Sqlite database on Android Studio
The best Sqlite debugging tool for android application is
Stetho By Facebook
http://facebook.github.io/stetho/
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. Developers can also choose to enable the optional dumpapp tool which offers a powerful command-line interface to application internals.
Download or Alternatively you can include Stetho from Maven Central via Gradle or Maven.
// Gradle dependency on Stetho
dependencies {
compile 'com.facebook.stetho:stetho:1.5.1'
}
<dependency>
<groupid>com.facebook.stetho</groupid>
<artifactid>stetho</artifactid>
<version>1.5.1</version>
</dependency>
Only the main stetho dependency is strictly required, however you may also wish to use one of the network helpers:
dependencies {
compile 'com.facebook.stetho:stetho-okhttp3:1.5.1'
}
Or
dependencies {
compile 'com.facebook.stetho:stetho-okhttp:1.5.1'
}
Or
dependencies {
compile 'com.facebook.stetho:stetho-urlconnection:1.5.1'
}
Integrations
Setup
Integrating with Stetho is intended to be seamless and straightforward for most existing Android applications. There is a simple initialization step which occurs in your Application class:
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
This brings up most of the default configuration but does not enable some additional hooks (most notably, network inspection). See below for specific details on individual subsystems.
Enable Network Inspection
If you are using the popular OkHttp library at the 2.2.x+ or 3.x release, you can use the Interceptors system to automatically hook into your existing stack. This is currently the simplest and most straightforward way to enable network inspection.
For OkHttp 2.x
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
For OkHttp 3.x
new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
As interceptors can modify the request and response, add the Stetho interceptor after all others to get an accurate view of the network traffic.
If you are using HttpURLConnection
, you can use StethoURLConnectionManager
to assist with integration though you should be aware that there are some caveats with this approach. In particular, you must explicitly add Accept-Encoding: gzip
to the request headers and manually handle compressed responses in order for Stetho to report compressed payload sizes.
for more info please visit stetho
Related Topics
How to Add a Button Dynamically in Android
Using Facebook Sdk in Android Studio
How to Create a Closed (Circular) Listview
Using Intent in an Android Application to Show Another Activity
Android Studio - How to Increase Allocated Heap Size
Accessing Localhost:Port from Android Emulator
Good Way of Getting the User's Location in Android
Java.Lang.Runtimeexception: Unable to Instantiate Activity Componentinfo
How to Add Manifest Permission to an Application
How to Disable an Android Button
Integrate Mupdf Reader in an App
Runtimeexception: Unable to Instantiate Application