2

i can access the my sqlite db using adb shell commands in my emulator. But can not do the same for my HTC Desire phone. it throws some permission denied messages. is there any possible to access those database for debugging purpose. Any Idea?

Thanks in Advance.

Praveen
  • 90,477
  • 74
  • 177
  • 219
  • Where is the database? In /data/data? If the phone is not rooted, you don't have access. You'll need to have your app copy it to the sdcard first, in that case. – EboMike Dec 17 '10 at 05:45
  • Where is your database stored? If its stored on SDCard, then you need to use the permission android.permission-group.STORAGE" in manifest. – Mudassir Dec 17 '10 at 05:46
  • @EboMike : Okay then How can i copy the app from phone? – Praveen Dec 17 '10 at 05:59
  • @Mudassir: I have stored my database into my app itself – Praveen Dec 17 '10 at 06:00
  • If you have stored the db on the internal storage, then it should be easily accessible. You should check your db logic from start. – Mudassir Dec 17 '10 at 06:07
  • @Mudassir: i have store it in internal memory only. but i can not access it – Praveen Dec 17 '10 at 06:17
  • You need to root your phone to access /data/data outside your app. If that's not an option, write debugging code in your app that takes the database file and copies it to anywhere on your SD card. A simple file copy code does the trick. Once it's on the SD card, you can access it through adb shell. – EboMike Dec 17 '10 at 06:53
  • possible duplicate of [How to access the database when developing on Android phone?](http://stackoverflow.com/questions/2811615/how-to-access-the-database-when-developing-on-android-phone) – Volo Apr 12 '12 at 12:55

3 Answers3

5

You can also type the following in to the command prompt/terminal

If your app package was com.example.dbtest and the database was called sqlite.db

adb shell

run-as com.example.dbtest

cat databases/sqlite.db > /sdcard/sqlite.db

exit

exit

adb pull /sdcard/sqlite.db /path/to/place/file

(if you leave the last parameter blank, it will be placed in the same directory as adb)

This does not require root and be scripted to remove any file from your apps.

You could also use a stream reader and writer to copy it to the sdcard. Do not copy it row by row as barmaley suggested as this may mask errors.

Ray Britton
  • 8,257
  • 3
  • 23
  • 32
2

I can see only 2 options:

  1. Get root access to your device
  2. Write special procedure, which will copy your database to SD card (just record by record using SQLite API)
Barmaley
  • 16,638
  • 18
  • 73
  • 146
  • Please elaborate your answer. how to get the root acces of my phone. – Praveen Dec 17 '10 at 06:02
  • Every phone is different. Google "root" for your phone model. CyanogenMod for examples is a popular rooted ROM that works on several popular phones. – EboMike Dec 17 '10 at 06:59
  • Please give me the steps to follow or guidelines to root my phone? – Praveen Dec 17 '10 at 11:01
  • 1
    Let me write it again. Every phone is different. There are different step for every phone. Depending on the phone you have, you need to take different steps. There are no generic steps that work on any phone. It depends on your phone. Please use Google to search for the steps that pertain to your particular phone. Enter the name of your phone model, and "root", and you are likely to find the steps that work for your particular phone. – EboMike Dec 17 '10 at 16:41
0

you dont need to rootor export you db . you can manage you android database directly from your apps using the below 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

sanath_p
  • 2,198
  • 2
  • 26
  • 22