Access to android files in cache directory

July 26, 2020
Using adb cli

You take a picture from your app, and get back an uri in return.

Then you proceed to upload the photo to server. End of story.

As a developer, you know that's not always the case, sometimes it's a bit more complicated, you take a snapshot from within the app, and realized that it returns black image.

So you want to debug, and without uploading to server, you can't access to the file, to take a look at the state of the image, whether your code changes has fixed the issue or not.

Or you want to manipulate the image before uploading.

For whatever reason, you want to access to the file in cache.

After few failed attempts to get it via tools like Android File Transfer and others that can access to the Android file system.

I found the solution with adb cli, and here is how to do it, from your Android device.

adb shell "run-as com.yourapp.bundle cat '/data/user/0/com.yourapp.bundle/cache/ReactNative-image1215816883788.jpg' > '/sdcard/DCIM/ReactNative-image1215816883788.jpg'"

adb pull "/sdcard/DCIM/ReactNative-image1215816883788.jpg"

That's it!

Now, check your current directory for the file ReactNative-image1215816883788.jpg