I'm generating a sqlite database on my desktop system, this database (file with .db extention) should be pushed to my Android app by USB cable. Is it possible? If yes, how?
Asked
Active
Viewed 1,686 times
2
-
Unless your device is rooted, you can't push a database into an app's private data folder – OneCricketeer Jan 18 '16 at 16:50
-
Looks like there is some confusion going on about whether your question is about pushing the db to an already installed app, or getting the db into the apk. Since getting the db into the apk would take care of either case, just do yourself a favor and use the SQLiteAssetHelper library: https://github.com/jgilfelt/android-sqlite-asset-helper – Daniel Nugent Jan 18 '16 at 19:58
2 Answers
1
Short answer on your question is Yes and No.
Yes - if your device is coming with android version 4.3 and below and in every case if your device is rooted. (I will explain procedure below for non-rooted and android <=4.3);
No - if your device is not rooted and android version is 4.4 and higher.
Assuming that your device is not rooted and version of android is 4.3 and minor, you have to perform next actions:
Changing permissions on current db:
adb shell
$ run-as your.package.name
$ cd ./databases/
$ chmod 666 ./dbname.db
$ exit
$ exit
Backing up the original db:
adb pull /data/data/your.package.name/databases/dbname.db /your/path/to/file/on/computer
Replacing current with new database:
adb push /your/path/to/file/on/computer/dbname.db /data/data/your.package.name/databases/dbname.db
Restoring original permissions:
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit
Also, note that you have to adapt paths and file names for your current situation.
If you have rooted phone, then you have to change permissions over su user. If you need that procedure, I can post it, also.

Bosko Mijin
- 3,287
- 3
- 32
- 45