Accessing Application Data via ADB Shell Without Mounting SD Card

Accessing Application Data via ADB Shell Without Mounting SD Card

21 May 2024 Stephan Petzl Leave a comment Tech-Help

Developers often need to access application data to monitor changes and debug issues. While it’s straightforward to view data stored on the SD card by mounting it on a PC, this approach is not always viable. For instance, if the application doesn’t operate correctly when the SD card is mounted, an alternative method is required.

In this article, we will explore how to access your app’s data using ADB shell without mounting the SD card.

Understanding Internal vs. External Storage

Android provides two types of storage for apps: internal and external. Internal storage is private to your application and other apps can’t access it (nor can the user). In contrast, external storage is readable by the user and other apps.

Accessing Internal Storage via ADB

To access files from your internal storage located at /data/data/com.yourappname, you can’t directly pull these files due to permission restrictions on non-rooted devices. However, you can use the following workaround:

  1. Move the file from internal to external storage using ADB shell:
  2. adb shell "run-as com.yourappname cat /data/data/com.yourappname/files/myfile.txt > /sdcard/Downloads/myfile.txt"
  3. Then, pull the file from the external storage:
  4. adb pull /sdcard/Downloads/myfile.txt

If you need to browse the files, use the shell to navigate through your app’s files:

adb shell
run-as com.yourappname
cd /data/data/com.yourappname
ls -all

Retrieving Specific App Files

If you’re looking to retrieve specific files like an SQLite database, you can use the following command:

adb exec-out run-as com.yourapp.bundleid cat "/data/data/com.yourapp.bundleid/databases/databasefile.db" > ~/Desktop/databasefile.db

Replace com.yourapp.bundleid with your app’s package name and databasefile.db with the actual database file name.

How Repeato Can Help

In the context of mobile app testing, automating these processes can save a significant amount of time and reduce human error. This is where Repeato, a no-code test automation tool, shines.

Repeato allows you to automate the testing process for your iOS and Android apps. With its built-in ADB functionality, you can seamlessly integrate ADB commands into your automated test sequences. This means you can automate the process of moving files from internal to external storage and vice versa as part of your test setup or teardown.

For more detailed guidance on using ADB with Repeato, please see our documentation.

In conclusion, while accessing application data via ADB shell can seem daunting at first, with the right commands and tools like Repeato, it becomes a streamlined and efficient process. Embrace the power of automation and enhance your testing workflow today.

Like this article? there’s more where that came from!