├── !Guide ├── Desktop.JPG └── ES File Explorer.jpg ├── DatabaseUtil.java ├── LICENSE └── README.md /!Guide/Desktop.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanraisshan/Android-Database-Viewer/d65ba6a812c7ea9d9a7c2ed7efff31613883e358/!Guide/Desktop.JPG -------------------------------------------------------------------------------- /!Guide/ES File Explorer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shanraisshan/Android-Database-Viewer/d65ba6a812c7ea9d9a7c2ed7efff31613883e358/!Guide/ES File Explorer.jpg -------------------------------------------------------------------------------- /DatabaseUtil.java: -------------------------------------------------------------------------------- 1 | package com.util; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileOutputStream; 8 | import java.nio.channels.FileChannel; 9 | 10 | /** 11 | * Shayan Rais (http://shanraisshan.com) 12 | * created on 8/17/2016 13 | */ 14 | public class DatabaseUtil { 15 | //You need to declare permission 16 | // 17 | //in your Manifest file in order to use this class 18 | 19 | //______________________________________________________________________________________________ 20 | 21 | //todo -> rename the database according to your application 22 | final static String DATABASE_NAME = "MyDatabase.sqlite"; 23 | //example WhatsApp : /data/data/com.whatsapp/databases/msgstore.db 24 | final static String FOLDER_EXTERNAL_DIRECTORY = Environment.getExternalStorageDirectory() + "/shanraisshan"; 25 | 26 | //______________________________________________________________________________________________ 27 | /** 28 | * Call this method from any activity in your app ( 29 | * for example -> DatabaseUtil.copyDatabaseToExtStg(MainActivity.this); 30 | * this method will copy the database of your application into SDCard folder "shanraisshan/MyDatabase.sqlite" (DATABASE_NAME) 31 | */ 32 | public static void copyDatabaseToExtStg(Context ctx) { 33 | //external storage file 34 | File externalDirectory = new File(FOLDER_EXTERNAL_DIRECTORY); 35 | if(!externalDirectory.exists()) 36 | externalDirectory.mkdirs(); 37 | File toFile = new File(externalDirectory, DATABASE_NAME); 38 | //internal storage file 39 | //https://developer.android.com/reference/android/content/Context.html#getDatabasePath(java.lang.String) 40 | File fromFile = ctx.getDatabasePath(DATABASE_NAME); 41 | //example WhatsApp : /data/data/com.whatsapp/databases/msgstore.db 42 | if (fromFile.exists()) 43 | copy(fromFile, toFile); 44 | } 45 | 46 | 47 | //______________________________________________________________________________________________ Utility function 48 | /** 49 | * @param fromFile source location 50 | * @param toFile destination location 51 | * copy file from 1 location to another 52 | */ 53 | static void copy(File fromFile, File toFile) { 54 | try { 55 | FileInputStream is = new FileInputStream(fromFile); 56 | FileChannel src = is.getChannel(); 57 | FileOutputStream os = new FileOutputStream(toFile); 58 | FileChannel dst = os.getChannel(); 59 | dst.transferFrom(src, 0, src.size()); 60 | src.close(); is.close(); 61 | dst.close(); os.close(); 62 | } catch (Exception e) { 63 | //todo in case of exception 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Shayan Rais 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-Database-Viewer 2 | Utility class for viewing Android Application Database by pulling it from internal storage. 3 | No root of android device is required. 4 | 5 | Description 6 | ---- 7 | If you don't want to use ***adb, 3rd party library or gradle dependency etc***, and just want the database file in your ***SD Card***, Android-Database-Viewer is the solution. 8 | 9 | Android-Database-Viewer is the utility class that pulls your application database into SD Card. 10 | 11 | The default save path is set to **sdcard/shanraisshan/your_database_file** 12 | 13 | *Note* 14 | ---- 15 | **Database Name:** 16 | 17 | > Don't forget to change the name of the database according to your application database name. 18 | > 19 | > You need to update the variable **DATABASE_NAME** in [DatabaseUtil.java](https://github.com/shanraisshan/Android-Database-Viewer/blob/master/DatabaseUtil.java) accordingly. 20 | 21 | ````java 22 | final static String DATABASE_NAME = "MyDatabase.sqlite"; 23 | ```` 24 | 25 | > **DATABASE_NAME** can be any name like 26 | > 27 | > 1. MyDatabase.sqlite 28 | > 29 | > 2. MyDatabase.db 30 | > 31 | > 3. msgstore.db *(WhatsApp database name)* 32 | > 33 | > 4. MyDatabase *(without extension)* 34 | 35 | ---- 36 | **Devices running Marshmallow or above:** 37 | 38 | > For devices running Marshmallow or above, make sure to check whether the *Storage* permission is granted in the application's setting or not. 39 | 40 | Changes in Android application 41 | ---- 42 | 43 | Declare permission in your AndroidManifest.xml 44 | ````java 45 | 46 | ```` 47 | 48 | Import [DatabaseUtil.java](https://github.com/shanraisshan/Android-Database-Viewer/blob/master/DatabaseUtil.java) class in your project 49 | ````java 50 | package com.util; 51 | 52 | import android.content.Context; 53 | import android.os.Environment; 54 | import java.io.File; 55 | import java.io.FileInputStream; 56 | import java.io.FileOutputStream; 57 | import java.nio.channels.FileChannel; 58 | 59 | /** 60 | * Shayan Rais (http://shanraisshan.com) 61 | * created on 8/17/2016 62 | */ 63 | public class DatabaseUtil { 64 | //You need to declare permission 65 | // 66 | //in your Manifest file in order to use this class 67 | 68 | //______________________________________________________________________________________________ 69 | 70 | //todo -> rename the database according to your application 71 | final static String DATABASE_NAME = "MyDatabase.sqlite"; 72 | //example WhatsApp : /data/data/com.whatsapp/databases/msgstore.db 73 | final static String FOLDER_EXTERNAL_DIRECTORY = Environment.getExternalStorageDirectory() + "/shanraisshan"; 74 | 75 | //______________________________________________________________________________________________ 76 | /** 77 | * Call this method from any activity in your app ( 78 | * for example -> DatabaseUtil.copyDatabaseToExtStg(MainActivity.this); 79 | * this method will copy the database of your application into SDCard folder "shanraisshan/MyDatabase.sqlite" (DATABASE_NAME) 80 | */ 81 | public static void copyDatabaseToExtStg(Context ctx) { 82 | //external storage file 83 | File externalDirectory = new File(FOLDER_EXTERNAL_DIRECTORY); 84 | if(!externalDirectory.exists()) 85 | externalDirectory.mkdirs(); 86 | File toFile = new File(externalDirectory, DATABASE_NAME); 87 | //internal storage file 88 | //https://developer.android.com/reference/android/content/Context.html#getDatabasePath(java.lang.String) 89 | File fromFile = ctx.getDatabasePath(DATABASE_NAME); 90 | //example WhatsApp : /data/data/com.whatsapp/databases/msgstore.db 91 | if (fromFile.exists()) 92 | copy(fromFile, toFile); 93 | } 94 | 95 | 96 | //______________________________________________________________________________________________ Utility function 97 | /** 98 | * @param fromFile source location 99 | * @param toFile destination location 100 | * copy file from 1 location to another 101 | */ 102 | static void copy(File fromFile, File toFile) { 103 | try { 104 | FileInputStream is = new FileInputStream(fromFile); 105 | FileChannel src = is.getChannel(); 106 | FileOutputStream os = new FileOutputStream(toFile); 107 | FileChannel dst = os.getChannel(); 108 | dst.transferFrom(src, 0, src.size()); 109 | src.close(); is.close(); 110 | dst.close(); os.close(); 111 | } catch (Exception e) { 112 | //todo in case of exception 113 | } 114 | } 115 | } 116 | ```` 117 | 118 | ---- 119 | Now simply call ***copyDatabaseToExtStg()*** method from any activity in your app 120 | ````java 121 | //calling from MainActivity 122 | DatabaseUtil.copyDatabaseToExtStg(MainActivity.this); 123 | ```` 124 | 125 | ---- 126 | 127 | View Database 128 | ---- 129 | Image shows **MyDatabase.sqlite** present in SD Card. 130 | 131 | ![alt tag](https://github.com/shanraisshan/Android-Database-Viewer/blob/master/!Guide/ES%20File%20Explorer.jpg) 132 | 133 | Open Database in Desktop 134 | ---- 135 | Transfer the database file into your PC. You can view the database file using [Sqllite Studio](http://sqlitestudio.pl/files/free/stable/win32/) 136 | ![alt tag](https://github.com/shanraisshan/Android-Database-Viewer/blob/master/!Guide/Desktop.JPG) 137 | --------------------------------------------------------------------------------