Android
data folder
access data
Android tips
file management

How to access data/data folder in Android device?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The /data/data/ directory on Android contains private application data — databases, shared preferences, cache files, and internal storage for each installed app. Accessing this directory is restricted by Android's security model, but developers need to reach it for debugging, database inspection, and troubleshooting. The methods available depend on whether the device is rooted, an emulator, or a debuggable build.

The easiest approach for debuggable apps:

  1. Open Android Studio > View > Tool Windows > Device Explorer
  2. Navigate to /data/data/<your.package.name>/
  3. Browse, download, or upload files directly

This works on:

  • Emulators: Full access to all app directories
  • Physical devices: Only for apps with android:debuggable="true" in the manifest (debug builds)

Method 2: ADB Shell (run-as)

Access your own app's data directory without root:

bash
1# Connect to the device
2adb shell
3
4# Switch to your app's context (debug builds only)
5run-as com.example.myapp
6
7# Now you're in /data/data/com.example.myapp/
8ls
9# cache  databases  shared_prefs  files
10
11# Read a database
12cat databases/mydb.db > /sdcard/mydb.db
13
14# Or copy files out using adb
15exit  # exit run-as
16exit  # exit adb shell
17adb exec-out run-as com.example.myapp cat databases/mydb.db > mydb.db

The run-as command only works for apps signed with a debug key or with android:debuggable="true".

Method 3: ADB Pull (Emulators Only)

On emulators (which typically run as root):

bash
1# Pull entire app data directory
2adb pull /data/data/com.example.myapp/ ./app-data/
3
4# Pull a specific file
5adb pull /data/data/com.example.myapp/databases/mydb.db ./mydb.db
6
7# List files
8adb shell ls /data/data/com.example.myapp/

This does not work on non-rooted physical devices — you get "Permission denied".

Method 4: Rooted Device

On a rooted device, you have unrestricted filesystem access:

bash
1adb shell
2su  # elevate to root
3
4# Browse any app's data
5ls /data/data/
6ls /data/data/com.whatsapp/databases/
7
8# Copy files to sdcard for extraction
9cp /data/data/com.example.app/databases/app.db /sdcard/
10exit
11exit
12
13adb pull /sdcard/app.db ./

Method 5: Backup and Extract (No Root)

Use adb backup to extract app data:

bash
1# Create a backup of the app
2adb backup -f backup.ab -noapk com.example.myapp
3
4# Convert to tar (requires Android Backup Extractor)
5java -jar abe.jar unpack backup.ab backup.tar
6
7# Extract
8tar xf backup.tar
9# Files are in apps/com.example.myapp/

Note: Many apps disable backups with android:allowBackup="false", which blocks this method.

Method 6: Content Providers (Programmatic Access)

Access other apps' shared data through content providers:

java
1// Access contacts (requires permission)
2Cursor cursor = getContentResolver().query(
3    ContactsContract.Contacts.CONTENT_URI,
4    null, null, null, null
5);
6
7// Access your own app's files directory programmatically
8File filesDir = getFilesDir();           // /data/data/<pkg>/files/
9File cacheDir = getCacheDir();           // /data/data/<pkg>/cache/
10File dbFile = getDatabasePath("my.db");  // /data/data/<pkg>/databases/my.db

Directory Structure

 
1/data/data/com.example.myapp/
2├── databases/          # SQLite databases
3│   └── mydb.db
4├── shared_prefs/       # SharedPreferences XML files
5│   └── settings.xml
6├── files/              # Internal file storage (getFilesDir())
7├── cache/              # Cache files (getCacheDir())
8├── app_webview/        # WebView data
9└── no_backup/          # Files excluded from auto-backup

Common Pitfalls

  • Permission denied on physical devices: adb pull /data/data/... only works on emulators or rooted devices. Use run-as or Device Explorer for debug builds on physical devices.
  • run-as fails on release builds: run-as requires android:debuggable="true". Release builds (from Play Store or signed with a release key) do not allow run-as.
  • Security risks of rooting: Rooting a device exposes all app data, including credentials and tokens. Never root a device that contains sensitive personal data.
  • Scoped storage (Android 10+): Starting with Android 10, apps have restricted access to external storage. Internal storage (/data/data/) access rules remain unchanged, but the methods to share files between apps have changed.
  • SELinux enforcement: Even with root, SELinux policies may prevent access to certain directories. Use setenforce 0 temporarily (development only) or check adb shell getenforce.

Summary

  • Use Android Studio Device Explorer for the easiest GUI-based access to debuggable apps
  • Use adb shell run-as <package> to access your own debug app's data on physical devices
  • Use adb pull on emulators where root access is available by default
  • Root access gives full filesystem access but carries security risks
  • The /data/data/<package>/ directory contains databases, shared preferences, cache, and internal files
  • Release builds restrict access to app data — plan your debugging workflow around debug builds

Course illustration
Course illustration

All Rights Reserved.