Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I view Android application specific cache?

Is there any way to dynamically view the application specific cache in Android? I'm saving images to the cache (/data/data/my_app_package/cache) and I'm 99% sure they're saving there, but not sure how long they're staying around.

When I look in the cache using the DDMS File Explorer within Eclipse, it's always empty. I've also tried examining the appropriate cache dir in ADB and again it's always empty.

Any suggestions?

like image 727
Karim Varela Avatar asked Mar 28 '12 22:03

Karim Varela


People also ask

How do I view app cache data on Android?

Open Settings and select Storage. In the resulting list, tap the Apps entry (Other Apps on Android 11 and earlier). This will take you to a list of all the apps installed on your phone. Choose the app whose cache you want to clear.

How do I access application cache?

On Android Studio you can use Device File Explorer to view /data/data/your_app_package/cache. Click View > Tool Windows > Device File Explorer or click the Device File Explorer button in the tool window bar to open the Device File Explorer.

Where is cached data on Android?

Open your browser. Android browser: Go to Menu > More > Settings or Menu > Settings > Privacy & Security. Chrome: Go to Menu > Settings > Privacy. Android browser: Tap Clear cache, Clear history, and Clear all cookie data as appropriate.


2 Answers

You may use this command for listing the files for your own debuggable apk:

adb shell run-as com.corp.appName ls /data/data/com.corp.appName/cache 

And this script for pulling from cache:

#!/bin/sh adb shell "run-as com.corp.appName cat '/data/data/com.corp.appNamepp/$1' > '/sdcard/$1'" adb pull "/sdcard/$1" adb shell "rm '/sdcard/$1'" 

Then you can pull a file from cache like this:

./pull.sh cache/someCachedData.txt 

Root is not required.

like image 109
Tamas Avatar answered Sep 22 '22 19:09

Tamas


Unless ADB is running as root (as it would on an emulator) you cannot generally view anything under /data unless an application which owns it has made it world readable. Further, you cannot browse the directory structure - you can only list files once you get to a directory where you have access, by explicitly entering its path.

Broadly speaking you have five options:

  • Do the investigation within the owning app

  • Mark the files in question as public, and use something (adb shell or adb pull) where you can enter a full path name, instead of trying to browse the tree

  • Have the owning app copy the entire directory to the SD card

  • Use an emulator or rooted device where adb (and thus the ddms browser's access) can run as root (or use a root file explorer or a rooted device)

  • use adb and the run-as tool with a debuggable apk to get a command line shell running as the app's user id. For those familiar with the unix command line, this can be the most effective (though the toolbox sh on android is limited, and uses its tiny vocabulary of error messages in misleading ways)

like image 36
Chris Stratton Avatar answered Sep 24 '22 19:09

Chris Stratton