Access Private Data on Android
--
According to the official developer documentation, here are the options for data storage on Android:
- Shared Preferences — Store private primitive data in key-value pairs.
- Internal Storage — Store private data on the device memory.
- External Storage — Store public data on the shared external storage.
- SQLite Databases — Store structured data in a private database.
- Network Connection — Store data on the web with your own network server.
Aside from the network connection option, the other options are all persisting data on device. Both SharedPreferences and SQlite Databases are private data stored on device. These files are not accessible to other applications or users unless you are on an emulator or rooted device. Here are a few ways how I access and inspect these private data for debugging during development.
Access private files
On an emulator or rooted device
If you are running an emulator or rooted device. You should have access to the private storage of the device. You can access the files from Android Studio GUI or via command line:
- GUI — In Android Studio, launch Android Device Monitor from the menu: Tools/Android/Android Device Monitor. Navigate to the File Explorer tab, then data/data/<your app package name>/. Find the file you are looking for, and you can push and pull a file from there.
- Command line — you can also push the file to device or pull the file from device via adb:
adb pull remote-dir local-dir <-- Copy from device to local machine
adb push local-dir remote-dir <-- Copy from local machine to device
On a non-rooted device
If you are not running on an emulator or rooted device. From command line:
adb shell
run-as <app-package-name>F
cd data/data/...
Now you can access the files on the internal storage of the device. To exit the shell, type exit.
exit <-- exit out of adb shell