Home » Android » java – How do I view my Realm file in the Realm Browser?

java – How do I view my Realm file in the Realm Browser?

Posted by: admin March 11, 2020 Leave a comment


I’ve just discovered Realm and wanted to explore it in more detail so I decided to create sample application and having a mess around with it. So far so good.

However, one thing I haven’t been able to work out just yet is how to view my database in the Realm Browser. How can this be done?

How to&Answers:

Currently the Realm Browser doesn’t support accessing databases directly on the device, so you need to copy the database from the emulator/phone to view it. That can be done by using ADB:

adb pull /data/data/<packagename>/files/ .

That command will pull all Realm files created using Realm.getInstance(new RealmConfiguration.Builder().build()) . The default database is called default.realm.

Note that this will only work on a emulator or if the device is rooted.


Now you can view Realm DB on Chrome browser using Stetho, developed by Facebook. By default, Stetho allows to view Sqlite, network, sharedpreferences but with additional plugin here allows to view Realm as well.

After configuring your Application class with above libraries, while app is running and connected, open Chrome browser and navigate chrome://inspect to see

enter image description here

Then Resources->Web Sql->default.realm

enter image description here


You can also pull your file from any NON-rooted device using the ADB shell and run-as command.

You can use these commands to pull from your app’s private storage a database named your_database_file_name located in the files folder:

adb shell "run-as package.name chmod 666 /data/data/package.name/files/your_database_file_name"

// For devices running an android version lower than Android 5.0 (Lollipop)
adb pull /data/data/package.name/files/your_database_file_name

// For devices running an Android version equal or grater
// than Android 5.0 (Lollipop)
adb exec-out run-as package.name cat files/your_database_file_name > your_database_file_name
adb shell "run-as package.name chmod 600 /data/data/package.name/files/your_database_file_name"


If you are lazy to get the realm database file every time with adb, you could add an export function to your android code, which send you an email with the realm database file as attachment.

Here an example:

public void exportDatabase() {

    // init realm
    Realm realm = Realm.getInstance(getActivity());

    File exportRealmFile = null;
    try {
        // get or create an "export.realm" file
        exportRealmFile = new File(getActivity().getExternalCacheDir(), "export.realm");

        // if "export.realm" already exists, delete

        // copy current realm to "export.realm"

    } catch (IOException e) {

    // init email intent and add export.realm as attachment
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, "YOUR MAIL");
    intent.putExtra(Intent.EXTRA_SUBJECT, "YOUR SUBJECT");
    intent.putExtra(Intent.EXTRA_TEXT, "YOUR TEXT");
    Uri u = Uri.fromFile(exportRealmFile);
    intent.putExtra(Intent.EXTRA_STREAM, u);

    // start email intent
    startActivity(Intent.createChooser(intent, "YOUR CHOOSER TITLE"));

Don’t forget to add this user permission to your Android Manifest file:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


For Android (No need to root your device)

To obtain a copy of any of Realm database on your device, go to Device File Explorer in Android Studio.

Navigate to /data/data/your.package.name/files/.

There you will find your *.realm files. Right click, then Save As. Make sure to synchronize before you save them.

Use Realm Browser or any of these to view *.realm files:

Enter image description here


There is a workaround. You can directly access the file from the device monitor. You can access this directory only when you are using an emulator or rooted device.

In Android Studio:


Menu ToolsAndroidAndroid Device MonitorFile Explorerdatadata → (Your Package Name) → files → *db.realm

Pull this file from the device:

Enter image description here

From Android Studio 3 canary 1, Device File Explorer has been introduced. You need to look the realm file here. Then, (select your package) → select the realm file → Right click and

Enter image description here

And open the file into the Realm Browser. You can see your data now.


You can access the realm file directly. Here is solution that I’ve used.

First you can copy the realm file that is located in ‘/data/data/packagename/files’ to Environment.getExternalStorageDirectory()+’/FileName.realm’:

public class FileUtil {
    public static void copy(File src, File dst) throws IOException {
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);

        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);

Realm realm = null;
try {
    realm = Realm.getInstance(this);
        File f = new File(realm.getPath());
        if (f.exists()) {
            try {
                FileUtil.copy(f, new File(Environment.getExternalStorageDirectory()+"/default.realm"));
            catch (IOException e) {
finally {
    if (realm != null)

Second, use the ADB tool to pull that file like this:

$ adb pull /sdcard/default.realm .

Now you can open the file in the Realm Browser.


Here’s a solution that doesn’t require your phone to be rooted, by making use of the run-as command present inside adb‘s shell. Only pre-condition is that you must have a debug build of your app installed on the target phone.

$ adb shell
$ run-as com.yourcompany.yourapp # pwd will return /data/data/com.yourcompany.yourapp
$ cp files/default.realm /sdcard
$ exit
$ exit
$ adb pull /sdcard/default.realm ~/Desktop # or wherever you want to put it

You’ll have a copy of the DB from any phone inside your local directory, which you can then load onto the Realm Browser.


You can now access it directly if you’re using an emulator.

First Log the path where the file is in the emulator as @bmunk says:

Log.d(TAG, "path: " + realm.getPath());

Second Search it and do right click on the file and choose “Save As”, on the dialog will appear the route where the file really is in your system.

enter image description here
You can copy the route from the Save As dialog

And then, just paste the route on the “Open Local File” dialog of Realm Studio.

(I’ve tested this in Windows only)


Here is my ready-to-use shell script.
Just change package name and your adb paths then the script will do the necessary.

NOT_PRESENT="List of devices attached"
ADB_FOUND=`${ADB_PATH}/adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
if [[ ${ADB_FOUND} == ${NOT_PRESENT} ]]; then
    echo "Make sure a device is connected"
    ${ADB_PATH}/adb shell "
        run-as ${PACKAGE_NAME} cp /data/data/${PACKAGE_NAME}/files/${DB_NAME} /sdcard/
    ${ADB_PATH}/adb pull "/sdcard/${DB_NAME}" "${DESTINATION_PATH}"
    echo "Database exported to ${DESTINATION_PATH}${DB_NAME}"

More details on this blog post : http://medyo.github.io/2016/browse-populate-and-export-realm-database-on-android/


Keeping it simple:

/Users/inti/Library/Android/sdk/platform-tools/adb exec-out run-as com.mydomain.myapp cat files/default.realm > ~/Downloads/default.realm


  1. Find the path to your adb install. If you’re using Android Studio then look at File > Project Structure > SDK Location > Android SDK Location and append platform-tools to that path.
  2. Use your app’s fully qualified name for the run-as argument
  3. Decide where you want to copy the realm file to

NB: The file is called default.realm because I haven’t changed its name when configuring it – yours may be different.


You have few options to view your android realm files:

  1. Like @Christian Melchior said you can pull your realm database from device and open it on your mac using OSX Realm Browser

  2. You can use third party Android Realm Browser I created, to make android development with realm little bit easier. App will show you all realm files on your device, and you can view all your realm files real time while testing your app.

  3. You can use Chrome browser Stetho Full description how to use Setho is provided by @Jemshit Iskendero answer.


Here is a shell for lazy people like me 🙂

The .realm file will be stored inside the tmpRealm/ folder next to the .sh file.

adb shell 'su -c "
cd /data/data/<packagename>/files
rm -rf /data/local/tmp/tmpRealm/
mkdir /data/local/tmp/tmpRealm/
cp /data/data/com.arefly.sleep/files/* /data/local/tmp/tmpRealm
chown shell.shell /data/local/tmp/tmpRealm/*
rm -rf ./tmpRealm/
adb pull /data/local/tmp/tmpRealm ./

Or if you prefer to let tmpRealm/ be on the SD card:

adb shell 'su -c "
cd /data/data/com.arefly.sleep/files
mount -o rw,remount $EXTERNAL_STORAGE/
rm -rf $EXTERNAL_STORAGE/tmpRealm
mkdir $EXTERNAL_STORAGE/tmpRealm
cp /data/data/com.arefly.sleep/files/* $EXTERNAL_STORAGE/tmpRealm
rm -rf ./tmpRealm/
# http://unix.stackexchange.com/a/225750/176808
adb pull "$(adb shell 'echo "$EXTERNAL_STORAGE"' | tr -d '\r')/tmpRealm" ./


  1. https://stackoverflow.com/a/28486297/2603230
  2. https://android.stackexchange.com/a/129665/179720