Skip to content

Commit dbb4a31

Browse files
Add guide for adding custom database files
1 parent 3ec02f6 commit dbb4a31

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ You will see something like this :
7575
- Android Default Emulator: run `adb forward tcp:8080 tcp:8080` and open http://localhost:8080
7676
- Genymotion Emulator: Enable bridge from configure virtual device (option available in genymotion)
7777

78-
### Getting address With toast, in case you missed the address log in logcat
78+
### Getting address with toast, in case you missed the address log in logcat
7979
As this library is auto-initialize, if you want to get the address log, add the following method and call
8080
```java
8181
public static void showDebugDBAddressLogToast(Context context) {
@@ -92,6 +92,28 @@ public static void showDebugDBAddressLogToast(Context context) {
9292
}
9393
```
9494

95+
### Adding custom database files
96+
As this library is auto-initialize, if you want to add custom database files, add the following method and call
97+
```java
98+
public static void setCustomDatabaseFiles(Context context) {
99+
if (BuildConfig.DEBUG) {
100+
try {
101+
Class<?> debugDB = Class.forName("com.amitshekhar.DebugDB");
102+
Class[] argTypes = new Class[]{HashMap.class};
103+
Method setCustomDatabaseFiles = debugDB.getMethod("setCustomDatabaseFiles", argTypes);
104+
HashMap<String, File> customDatabaseFiles = new HashMap<>();
105+
// set your custom database files
106+
customDatabaseFiles.put(ExtTestDBHelper.DATABASE_NAME,
107+
new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +
108+
"/" + ExtTestDBHelper.DATABASE_NAME));
109+
setCustomDatabaseFiles.invoke(null, customDatabaseFiles);
110+
} catch (Exception ignore) {
111+
112+
}
113+
}
114+
}
115+
```
116+
95117
### Find this project useful ? :heart:
96118
* Support it by clicking the :star: button on the upper right of this page. :v:
97119

app/src/main/java/com/sample/utils/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void setCustomDatabaseFiles(Context context) {
5959
Class[] argTypes = new Class[]{HashMap.class};
6060
Method setCustomDatabaseFiles = debugDB.getMethod("setCustomDatabaseFiles", argTypes);
6161
HashMap<String, File> customDatabaseFiles = new HashMap<>();
62-
// set custom database files
62+
// set your custom database files
6363
customDatabaseFiles.put(ExtTestDBHelper.DATABASE_NAME,
6464
new File(context.getFilesDir() + "/" + ExtTestDBHelper.DIR_NAME +
6565
"/" + ExtTestDBHelper.DATABASE_NAME));

0 commit comments

Comments
 (0)