I am presently working on an WiFi application for Android. I am having trouble trying to access the database on the device. Debugging in the emulator doesn’t work for me, because there is no WiFi support in the emulator. I tried pulling the database file out of the device by using
adb pull data/data/package-name/databases/database-name
But I get the error “Permission denied.”.
In this answer Android: Where are database files stored?, Commonsware has suggested to pull database file by running in debug mode. But it doesn’t work too. Any help on how to debug the database without rooting the device would be much appreciated.
I’ll repeat myself from another answer:
Copy files to external storage on the device
So if you wish to pull your application database from the device you can launch a debug build of the application from Android Studio, connect with
adb shelland run the following command:or you can use a shorter version which uses relative paths and by skipping the reference to the home directory
~can omit thesh -cpart too:This will copy your
db-file.dbto the root of your SD card / external storage. Now you can easily get it from there by using file manager,adb pullor whatever else you like. Note that with this approach, there is NO need for your app to haveWRITE_EXTERNAL_STORAGEpermission, as the copying is done by theshelluser who can always write to the external storage.Copy files directly to the computer
You can also copy a database directly to your computer with the following command:
The
adb shellcommand above will not work correctly on Windows host because of theCR/LFsymbols conversion, unless you run it from abashshell or use the undocumentedadb exec-outcommand instead (some comments mention they still cannot get it to work correctly on a Windows machine, so your mileage may vary):Write files back to the device
If you modified the file on your computer and wish to write the modifications back to the device use the following command:
or if you prefer an
adb shellversion over undocumentedexec-in, use the following (but read the concern about the WindowsCR/LFconversion above):Status update
All the commands above are still working as of July, 2023