How to Retrieve Database Files from Internal Storage on Android

How to Retrieve Database Files from Internal Storage on Android

30 November 2024 Stephan Petzl Leave a comment Tech-Help

Accessing database files on a non-rooted Android device can be challenging due to the inherent security restrictions. However, for developers who need to debug applications without rooting their devices, there are methods to retrieve these files using ADB commands. This guide will walk you through the process of extracting database files using the run-as command.

Method 1: Using ADB Exec-Out Command

This method is suitable for Android devices running version 5.1 and above. The adb exec-out command allows you to access files within the app’s data directory:

adb exec-out run-as debuggable.app.package.name cat databases/file > file

For multiple files, you can use the tar command:

adb exec-out run-as debuggable.app.package.name tar c databases/ > databases.tar

These commands will create a copy of the database files on your local machine, allowing you to view and manipulate them using database tools.

Method 2: Copy Files via SD Card

If the direct method is blocked, you can copy the files to your device’s SD card and then pull them to your computer. Follow these steps:

  • Open ADB shell and switch to your app’s user space:
adb shell
run-as com.example.package
chmod 666 databases/file
exit
  • Copy the file to the SD card:
  • cp /data/data/package.name/databases/file /sdcard/
  • Pull the file from the SD card to your computer:
  • adb pull /sdcard/file .

    Remember to reset the file permissions after copying:

    run-as com.example.package
    chmod 600 databases/file

    Method 3: Using Device File Explorer

    For those using Android Studio, the Device File Explorer offers a straightforward way to access database files:

    • Open the Device File Explorer in Android Studio.
    • Select your device and navigate to the data/data directory.
    • Locate your application’s package and find the databases folder.
    • Right-click on the desired database file and choose the option to save it locally.

    Enhancing Your Testing Workflow with Repeato

    While accessing database files is crucial, efficient testing is equally important. Repeato, our no-code test automation tool for iOS and Android, can streamline your testing process. With Repeato, you can create and run automated tests for your apps quickly and efficiently. Leveraging computer vision and AI, Repeato ensures fast editing and execution of tests. Additionally, Repeato incorporates ADB, allowing you to execute ADB commands through script steps, facilitating precise timing and sequencing of commands. For more on Repeato, explore our documentation and Android testing tool page.

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