Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the database when developing on Android phone? [duplicate]

I am having trouble accessing the database while I am developing on the phone. Whenever I execute

cd /data/data/com.mycompck/databases

and then run ls I get: "opendir failed, Permission denied"

Or whenever I type in sqlite3 I get: "sqlite3: permission denied"

What am I doing wrong?

Are there some applications that can help me getting a human view of content resolvers values and/or SQLite databases?

like image 827
Pentium10 Avatar asked May 11 '10 14:05

Pentium10


2 Answers

Check my answer from the following thread: Why do I get access denied to data folder when using adb?

Starting from API level 8 (Android 2.2), if you build the application as debuggable, you can use the shell run-as command to run a command or executable as a specific user/application or just switch to the UID of your application so you can access its data directory.

So basically you will need to make a debug build (which is made automatically whenever you launch the application from the Android Studio unless you request the release build) and run the following commands:

run-as com.mycompck
cd /data/data/com.mycompck/databases
ls
sqlite3 ./yourdatabase.db

However note that sqlite3 binary is not present by default on many phones. Thus you will perhaps need to download it somewhere (e.g. from SuperOneClick archives at http://shortfuse.org/), save on the SD card and make it executable (which is a little bit tricky though), for example:

run-as com.mycompck
cd /data/data/com.mycompck/
cat /sdcard/sqlite3 >./sqlite3
chmod 744 ./sqlite3
./sqlite3 ./databases/yourdatabase.db
like image 67
Idolon Avatar answered Nov 12 '22 19:11

Idolon


To answer the first part of your question, check out this answer. Basically, your phone needs to have root access, and you need to run adb in root mode (using "adb root").

As for the second part, I use SQLite Database Browser to view my SQLite dbs (though that's only when the db is on my computer; don't know of any on-device browsers). I don't know of any way to get a human view of content resolvers.

like image 1
Dan Lew Avatar answered Nov 12 '22 19:11

Dan Lew