10

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?

Alex P.
  • 30,437
  • 17
  • 118
  • 169
Pentium10
  • 204,586
  • 122
  • 423
  • 502

5 Answers5

17

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
Community
  • 1
  • 1
Volo
  • 28,673
  • 12
  • 97
  • 125
  • So you're copying sqlite3 to the app's directory and then changing permissions to executable. I'm guessing this will mean a copy of sqlite3 will live in that directory until the app is deleted off the phone. So my question is: does reinstalling the app delete the executable (for example, clicking RUN in Eclipse)? – styfle Dec 08 '11 at 19:37
  • 1
    @styfle Your application database and shared preferences aren't deleted when you click "Run" in Eclipse, are they? So do sqlite3 executable. Only `adb uninstall` (without `-k` option) will delete it (or manual application uninstall through the device Application Manager). – Volo Dec 09 '11 at 18:15
  • Do I need to do anything in Idea13CE (community edition) to ensure the it's making a debug build? – rup3rt Oct 01 '13 at 04:55
1

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.

Community
  • 1
  • 1
Dan Lew
  • 85,990
  • 32
  • 182
  • 176
  • Why do I need root access, I want to access my applications data, as I am the developer I would love to get access to it. – Pentium10 May 11 '10 at 14:44
  • adbd cannot run as root in production builds – Pentium10 May 11 '10 at 14:46
  • 4
    Add an export or backup function to your app that copies the database to the SD card. – CommonsWare May 11 '10 at 15:26
  • @Pentium10: Because that's the way it works, access to the data directory is locked for non-root access. I don't make the rules. :P CommonsWare is correct though, that's a decent workaround. – Dan Lew May 11 '10 at 15:30
  • @Pentium10 Things has changed a little since 2010 :) Check [my answer](http://stackoverflow.com/a/8433520/648313) below. – Volo Dec 08 '11 at 16:53
  • @CommonsWare Thanks.. very simple thought...Keep making people a Busy coder. – IronBlossom May 10 '12 at 13:30
0

The best way to view and manage your android app database is to use this 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
0

You have to be root to access any database file. So, you can either get root on your phone (look for information on Google) or debugging the database just from the emulator (wich gives you root access always).

Bye!

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • Unfortunately I can't debug from Emulator the database as the emulator doesn't have the apps I am using (Agenda, Bluetooth, Wifi). – Pentium10 May 11 '10 at 14:49
  • But you can install those apps to the emulator: adb install appname.apk Anyway, I highly recommend to root your phone :) http://www.google.com.co/search?q=root+android – Cristian May 11 '10 at 15:20
-1

I've read up on this a little and accessing your database files for mobile seems quite of a hassle.

Take a look at this. with this you can view your database inside of your application. Database Manager

For me this worked fine. It kind of also depends on what you're planning to do ofcourse.

Hope it helps.

Feddex
  • 43
  • 10
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/16161779) – S.L. Barth is on codidact.com May 18 '17 at 11:08
  • good point. but still, its a great way to manage your Mobile Databases – Feddex May 18 '17 at 11:50