45

I have tested creating, inserting and retrieving data into my apps db, and know it works through usage of Log statements.

However, I wish to expedite testing and use the Android Device Monitor. However, though the db exists and data is stored, when accessing below, the data folder is empty:

enter image description here

Why would this be the case? How can this be configured to show the db file and contents?

Sauron
  • 6,399
  • 14
  • 71
  • 136

9 Answers9

44

Solving the issue using an emulator

The folder /data can be empty because you are missing the proper permissions. To solve it, I had to execute the following commands.

adb shell
su

Those commands starts a shell in the emulator and grant you root rights. The command adb is located in the folder platform-tools of the Android SDK, typically installed in ~/Library/Android/sdk/ on MacOS.

chmod -R 777 /data

Modify the permissions of the folder (and subfolders recursively) /data in order to make them appear in the tool Android Device Monitor.

adb root

Finally, this command restarts adb as root. Be careful, it only works on development builds (typically emulators builds).

Afterwards, you can see the content of the folder /data and transfer the data located in. You can do it in console as well, using adb pull <remote> <locale>, such as:

adb pull /data/data/<app name>/databases/<database> .
Jämes
  • 6,945
  • 4
  • 40
  • 56
24

In addition to @Steven K's answers: If you want to gain access to your data without having to root your real device you need to run your app in an emulator with API 23 (or lower). It is a known problem that APIs above 23 can cause problems when deploying Android Device Monitor.

Jonathan Rhein
  • 1,616
  • 3
  • 23
  • 47
10

If anyone is having the stated problem, follow below steps in terminal window:

  1. Navigate to /Users/Username/Library/Android/sdk/platform-tools
  2. Execute ./adb root

That's it. Problem solved.

8

It isn't empty....you just don't have permission to view that folder on a device.

Try it in a simulator and it will work for you since you have root access.

Steven K
  • 393
  • 3
  • 12
6

There are two ways if you want to browse your device data (data/data) folder.

  1. You need to have a phone with root access in order to browse the data folder using ADM(Android Device Monitor).

ADM location - (YOUR_SDK_PATH\Android\sdk\tools)

  1. You need to be running ADB in root mode, do this by executing: adb root

If you just want to see your DB & Tables then the esiest way is to use Stetho. Pretty cool tool for every Android developer who uses SQLite buit by Facobook developed.

Steps to use the tool

  1. Add below dependeccy in your application`s gradle file (Module: app)

'compile 'com.facebook.stetho:stetho:1.4.2'

  1. Add below lines of code in your Activity onCreate() method
@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 Stetho.initializeWithDefaults(this);
 setContentView(R.layout.activity_main);
 }

Now, build your application & When the app is running, you can browse your app database, by opening chrome in the url:

chrome://inspect/#devices

Screenshots of the same are as below_

ChromeInspact

ChromeInspact

Your DB

Your DB

Hope this will help all! :)

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
5

It may be easier to store the database in a public folder during development.

Or you can see this post :

How to access data/data folder in Android device?

Community
  • 1
  • 1
Steven K
  • 393
  • 3
  • 12
  • Can you please outline how to accomplish this? – Sauron Jan 05 '16 at 03:01
  • 2
    File dbfile = new File("/sdcard/mydb.sqlite" ); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null); System.out.println("Its open? " + db.isOpen – Steven K Jan 05 '16 at 03:07
3

In cmd GoTo:

C:\Users\UserName\android-sdks\platform-tools

Execute:

adb root

Done

Blue
  • 22,608
  • 7
  • 62
  • 92
Rubel
  • 1,255
  • 14
  • 18
1

I had same problem with API_25, it didn't work for me.

Configure an API_23 emulator, it will work on API_23.

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
1

If you are on Windows follow these instructions step by step:

  1. Launch your app in android emulator.
  2. Then open command prompt as an administrator and navigate to the sdk path for example cd C:\Android\sdk\platform-tools
  3. Type adb root
  4. Then type adb pull /data/data/ name-of-your-package /databases/name-of-your-database
  5. You'll find your database located in the folder called platform-tools.

Then you can install Sqlite Manager extension in Google Chrome via chrome webstore and use it to view and manage your exported database.

In case you have a rooted phone you can follow the same instructions as above.

CKE
  • 1,533
  • 19
  • 18
  • 29
Nelson Katale
  • 1,309
  • 15
  • 21