Skip to content

Commit d70de09

Browse files
Update README.md
1 parent 93bb3ca commit d70de09

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed

README.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,192 @@
1+
<img src=https://raw.githubusercontent.com/amitshekhariitbhu/Android-Debug-Database/master/assets/debug_db_banner.png >
12

3+
# Android Debug Database
4+
5+
## Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications
6+
7+
### Android Debug Database allows you to view databases and shared preferences directly in your browser in a very simple way
8+
9+
### What can Android Debug Database do?
10+
11+
* See all the databases.
12+
* See all the data in the shared preferences used in your application.
13+
* Run any sql query on the given database to update and delete your data.
14+
* Directly edit the database values.
15+
* Directly edit the shared preferences.
16+
* Directly add a row in the database.
17+
* Directly add a key-value in the shared preferences.
18+
* Delete database rows and shared preferences.
19+
* Search in your data.
20+
* Sort data.
21+
* Download database.
22+
* Debug Room inMemory database.
23+
24+
## [My Personal Blog - amitshekhar.me](https://amitshekhar.me/blog) - High-quality content to learn Android concepts.
25+
26+
### All these features work without rooting your device -> No need of rooted device
27+
28+
### Using Android Debug Database Library in your application
29+
30+
Add this to your app's build.gradle
31+
32+
```groovy
33+
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'
34+
```
35+
36+
Using the Android Debug Database with encrypted database
37+
38+
```groovy
39+
debugImplementation 'com.amitshekhar.android:debug-db-encrypt:1.0.6'
40+
```
41+
And to provide the password for the DB, you should add this in the Gradle:
42+
DB_PASSWORD_{VARIABLE}, if for example, PERSON is the database name: DB_PASSWORD_PERSON
43+
```groovy
44+
debug {
45+
resValue("string", "DB_PASSWORD_PERSON", "password")
46+
}
47+
```
48+
49+
Use `debugImplementation` so that it will only compile in your debug build and not in your release build.
50+
51+
That’s all, just start the application, you will see in the logcat an entry like follows :
52+
53+
* D/DebugDB: Open http://XXX.XXX.X.XXX:8080 in your browser
54+
55+
* You can also always get the debug address url from your code by calling the method `DebugDB.getAddressLog();`
56+
57+
Now open the provided link in your browser.
58+
59+
Important:
60+
61+
* Your Android phone and laptop should be connected to the same Network (Wifi or LAN).
62+
* If you are using it over usb, run `adb forward tcp:8080 tcp:8080`
63+
64+
Note : If you want use different port other than 8080.
65+
In the app build.gradle file under buildTypes do the following change
66+
67+
```groovy
68+
debug {
69+
resValue("string", "PORT_NUMBER", "8081")
70+
}
71+
```
72+
73+
You will see something like this :
74+
75+
### Seeing values
76+
77+
<img src=https://raw.githubusercontent.com/amitshekhariitbhu/Android-Debug-Database/master/assets/debugdb.png >
78+
79+
### Editing values
80+
81+
<img src=https://raw.githubusercontent.com/amitshekhariitbhu/Android-Debug-Database/master/assets/debugdb_edit.png >
82+
83+
### Working with emulator
84+
85+
* Android Default Emulator: Run the command in the terminal - `adb forward tcp:8080 tcp:8080` and open http://localhost:8080
86+
* Genymotion Emulator: Enable bridge from configure virtual device (option available in genymotion)
87+
88+
### Getting address with toast, in case you missed the address log in logcat
89+
90+
As this library is auto-initialize, if you want to get the address log, add the following method and call (we have to do like this to avoid build error in release build as this library will not be included in the release build) using reflection.
91+
92+
```java
93+
public static void showDebugDBAddressLogToast(Context context) {
94+
if (BuildConfig.DEBUG) {
95+
try {
96+
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
97+
Method getAddressLog = debugDB.getMethod("getAddressLog");
98+
Object value = getAddressLog.invoke(null);
99+
Toast.makeText(context, (String) value, Toast.LENGTH_LONG).show();
100+
} catch (Exception ignore) {
101+
102+
}
103+
}
104+
}
105+
```
106+
107+
### Adding custom database files
108+
109+
As this library is auto-initialize, if you want to debug custom database files, add the following method and call
110+
111+
```java
112+
public static void setCustomDatabaseFiles(Context context) {
113+
if (BuildConfig.DEBUG) {
114+
try {
115+
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
116+
Class[] argTypes = new Class[]{HashMap.class};
117+
Method setCustomDatabaseFiles = debugDB.getMethod("setCustomDatabaseFiles", argTypes);
118+
HashMap<String, Pair<File, String>> customDatabaseFiles = new HashMap<>();
119+
// set your custom database files
120+
customDatabaseFiles.put(ExtTestDBHelper.DATABASE_NAME,
121+
new Pair<>(new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +
122+
"/" + ExtTestDBHelper.DATABASE_NAME), ""));
123+
setCustomDatabaseFiles.invoke(null, customDatabaseFiles);
124+
} catch (Exception ignore) {
125+
126+
}
127+
}
128+
}
129+
```
130+
131+
### Adding InMemory Room databases
132+
133+
As this library is auto-initialize, if you want to debug inMemory Room databases, add the following method and call
134+
135+
```java
136+
public static void setInMemoryRoomDatabases(SupportSQLiteDatabase... database) {
137+
if (BuildConfig.DEBUG) {
138+
try {
139+
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
140+
Class[] argTypes = new Class[]{HashMap.class};
141+
HashMap<String, SupportSQLiteDatabase> inMemoryDatabases = new HashMap<>();
142+
// set your inMemory databases
143+
inMemoryDatabases.put("InMemoryOne.db", database[0]);
144+
Method setRoomInMemoryDatabase = debugDB.getMethod("setInMemoryRoomDatabases", argTypes);
145+
setRoomInMemoryDatabase.invoke(null, inMemoryDatabases);
146+
} catch (Exception ignore) {
147+
148+
}
149+
}
150+
}
151+
```
152+
153+
### Find this project useful ? :heart:
154+
155+
* Support it by clicking the :star: button on the upper right of this page. :v:
156+
157+
### TODO
158+
159+
* Simplify emulator issue [Issue Link](https://github.com/amitshekhariitbhu/Android-Debug-Database/issues/6)
160+
* And of course many more features and bug fixes.
161+
162+
You can connect with me on:
163+
164+
- [Twitter](https://twitter.com/amitiitbhu)
165+
- [LinkedIn](https://www.linkedin.com/in/amit-shekhar-iitbhu)
166+
- [GitHub](https://github.com/amitshekhariitbhu)
167+
- [Facebook](https://www.facebook.com/amit.shekhar.iitbhu)
168+
169+
[**Read all of my blogs here.**](https://amitshekhar.me/blog)
170+
171+
### License
172+
173+
```
174+
Copyright (C) 2022 Amit Shekhar
175+
176+
Licensed under the Apache License, Version 2.0 (the "License");
177+
you may not use this file except in compliance with the License.
178+
You may obtain a copy of the License at
179+
180+
http://www.apache.org/licenses/LICENSE-2.0
181+
182+
Unless required by applicable law or agreed to in writing, software
183+
distributed under the License is distributed on an "AS IS" BASIS,
184+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185+
See the License for the specific language governing permissions and
186+
limitations under the License.
187+
```
188+
189+
### Contributing to Android Debug Database
190+
191+
All pull requests are welcome, make sure to follow the [contribution guidelines](CONTRIBUTING.md)
192+
when you submit pull request.

0 commit comments

Comments
 (0)