11

I'm trying to access the sqlite database file on the device. I mean, I've launched the app on the device via adb. And now I wanto to download this file as I did before on emulator via DDMS. But when I select the device on DDMS and open the folder data, it is empty.

Is it the right way to do? Or there is another way to download this db file.

Thanks.

Namphibian
  • 12,046
  • 7
  • 46
  • 76
rogcg
  • 10,451
  • 20
  • 91
  • 133
  • [View SQLite database on device in Android Studio](http://stackoverflow.com/questions/28220636/view-sqlite-database-on-device-in-android-studio) This for me is the easiest way to do it.Check it out – Ojonugwa Jude Ochalifu Jun 24 '15 at 06:23

2 Answers2

36

You can access to the data folder without root, provided the application is debuggable

<application
 ...
        android:debuggable="true"
 ...

To list the base directory :

adb shell "run-as com.your.package ls -l"

To copy a file :

adb shell "run-as com.your.package cat relative/path > /sdcard/some_name"
adb pull /sdcard/some_name

Unfortunately pre-ICS run-as is quite buggy. The usual symptom is a

run-as: Package 'com.your.package' is unknown

message.

bwt
  • 17,292
  • 1
  • 42
  • 60
  • Then just use something like http://sourceforge.net/projects/sqlitebrowser/ to read the file. sudo aptitude install sqlitebrowser – redochka May 18 '13 at 16:05
  • 1
    There is no need to set android:debuggable="true" in manifest as you compile a project from debug certificate it will automatically set to true. – Ankit Jul 30 '13 at 14:36
  • When running this on an emulator I got the error: `/system/bin/sh: can't create /sdcard/habits.db: Read-only file system` In order to write I needed to remount the filesystem: http://stackoverflow.com/questions/2083709/android-emulator-sdcard-push-error-read-only-file-system#answer-3296673 – dysbulic Sep 19 '13 at 15:48
  • 1
    What should I do when the resulting file is empty? – Andrew Orobator Jan 10 '15 at 22:41
  • 1
    @AndrewOrobator I've got better solution: http://stackoverflow.com/a/29257875/291427 – kmalmur Mar 25 '15 at 14:22
  • what is `relative/path` should I replace it? I'm getting `relative/path: No such file or directory` – Hesam Jun 17 '15 at 08:54
3

Have you tried adb directly?

adb pull /data/data/the.package.of.the.app/databases/the_name_of_the_database.db
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • 3
    This probably won't work on non-rooted devices – Damp Jan 31 '11 at 21:22
  • yeah. but the data folder is empty. I click and the hierarchy three doesnt open. just shows the data folder, I dont know why. =/ – rogcg Jan 31 '11 at 21:51
  • @Damp you are right... it's still hard for me to think of a android developer with a non-rooted phone. – Cristian Jan 31 '11 at 21:52
  • 1
    @rogcg the /data/ directory is not empty. It just doesn't show anything in it because you are probably using a non-rooted phone. This is a protection mechanism because it keeps developers from snooping around at other people's apps on our phones. Unfortunately it also keeps you from looking at your own apps data... – Jake Wilson Oct 31 '11 at 22:09
  • It will work on non-rooted devices as long as you have access to the file, which can be granted from the app itself. See: http://stackoverflow.com/a/24705519/1002098 – delrocco Jul 11 '14 at 19:56
  • I have rooted but it just shows data folder – Hoo Nov 06 '15 at 07:08