How do I pull the sqlite database from the android device like emulator?
-
This will be the latest answer https://stackoverflow.com/a/51587416/5257674 – Waqas Ahmed Sep 21 '18 at 06:46
10 Answers
You can use these commands for pulling the data base from your device. Typing these commands through android studio is very easy. Please make sure you have set the path of adb globally to your system. Then open the "terminal" window from bottom to android studio and near to "Android Monitor". Now you just update the following commands with actual package name of your app and database file name. You will get your file out from the device.
adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"
adb pull /data/data/package.name/databases/file .
adb shell "run-as package.name chmod 600 /data/data/package.name/databases/file"
the command for Android 5.0+ /data/data/package.name/databases/file would be:
adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"
adb exec-out run-as package.name cat databases/file > newOutFileName
adb shell "run-as package.name chmod 600 /data/data/package.name/databases/file"

- 6,472
- 2
- 23
- 29
-
Perfect. If you want to inspect the data folder first, have a look at this post: http://stackoverflow.com/questions/9017073/is-it-possible-to-see-application-data-from-adb-shell-the-same-way-i-see-it-moun – shadowhorst Jun 26 '15 at 18:04
-
-
@Rajeev Kumar -I have update the answer for devices with version greater than Lolipop. One more thing I want to address is that this commonds generally does not works for Samsumg devices. May be samsung devices have some restrictions or issues Please take care before use. – Manmohan Soni Apr 25 '17 at 14:05
You can use Android Device Monitor to pull it. Go to Tools -> Android -> Android Device Monitor
- Select your device from the left list.
- Select FileExplorer tab
- Expand data-> data -> "yourpackageName" -> databases
- Select your databaseFile and on the top right click on this icon
pull a file form a device.
- Save it on your desk then use this tool to open it: http://sqlitebrowser.org/

- 6,573
- 1
- 31
- 54

- 1,035
- 1
- 10
- 16
- connect your device to pc
- open command prompt in
/sdk-directory/tools
- type
adb pull /data/data/com.example.app/databases/database.db
where com.example.app
is your application package name and database.db
is the database file
that's in case your device is rooted, if not try following
-
-
Same issue where pull not showing any tables. I know this is old but any solution for this? – cvb May 10 '19 at 18:38
from version 24 onwards i use these commands to pull database
adb shell
run-as package.name
cat /databases/database.db > /sdcard/database.db
exit
exit
adb pull /sdcard/database.db
prior to version 24
adb pull /data/data/package name/databases/database.db
was sufficient

- 1,978
- 24
- 29
The best way to view and manage you android app database is to use this library https://github.com/sanathp/DatabaseManager_For_Android
Its a single java activity file ,just add the java file to your source folder you can view the tables in your app database , update ,delete, insert rows to you table .Everything from your app.
When the development is done remove the java file from your src folder thats it .
It helped me a lot .Hope it helps you too .
You can view the 1 minute demo here : http://youtu.be/P5vpaGoBlBY

- 2,198
- 2
- 26
- 22
You can skip all those middle stages with one command.
In your PC shell run:
adb -d shell 'run-as <package_name> cat /data/data/<package_name>/databases/<db_name>' > <local_file_name>

- 125
- 1
- 2
- 3
I know this is an old question, however this is what I did to pull the SQLite Database file from app on device.
- Saving the file from app package to device sdcard
adb -d shell "run-as com.dautechnology.abdimuna.smartparking cat /data/data/<myAppPackageName>/databases/<databaseFileName> > /sdcard/<databaseFileName>"
The above command will store file to /sdcard
You can verify the file by
adb shell
ls sdcard/
Then exit from adb shell by typing exit
- Pull the file from sdcard to your current working location.
adb pull sdcard/<databaseFileName>
- Move the file to Desktop or place of your desire.
mv <databseFileName> ~/Desktop
I hope this helps someone out there.
Do it programatically in application
try {
File file = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (file.canWrite()) {
String currentPath = "/data/data/" + getPackageName() + "/databases/yourdbname";
String copyPath = "copydb_name.db";
File currentDB = new File(currentPath);
File backupDB = new File(file, copyPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
Make sure given permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If you use eclipse then go to DDMS view . from File Explorer Tab ->data->data->application package name->databases-> databse name
select database db file then click pull button

- 4,134
- 2
- 26
- 37