How do I view my Realm file in the Realm Browser?
Solution 1
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.
Solution 2
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
Then Resources->Web Sql->default.realm
Solution 3
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"
Solution 4
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
exportRealmFile.delete();
// copy current realm to "export.realm"
realm.writeCopyTo(exportRealmFile);
} catch (IOException e) {
e.printStackTrace();
}
realm.close();
// init email intent and add export.realm as attachment
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
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" />
Solution 5
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:
Comments
-
Andy Joyce almost 3 years
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?
-
bmunk about 9 yearsYou can also log the exact path from your app with: Log.d("", "path: " + realm.getPath());
-
ymerdrengene almost 9 yearsThis is especially good if you use Pushbullet. Then you can push a message to your Chrome browser and it will download the file. The file can then be opened in Realm Browser
-
careful7j over 8 yearsFailed to resolve: com.uphyca:stetho_realm:0.8.0 May anyone help me with this? I am sorry, I am not a mac user, so it looks like this way is the only I can browse my database file.
-
Jemshit Iskenderov over 8 yearsDid you add url
https://github.com/uPhyca/stetho-realm/raw/master/maven-repo
as shown here github.com/uPhyca/stetho-realm -
careful7j over 8 yearsMy fault, thank you very much! I have missed this. Now it works as it should!
-
Jemshit Iskenderov over 8 yearsSo Realm Browser for Mac is useless. Who uses emulator
-
AlexKost over 7 yearsDoes the browser updates it's content in real time? After I set it up it shows the same content each time whereas content changes. Even after app deleting-installing again I expected realm to be empty, but it still shows the same content. Any ideas?
-
Jemshit Iskenderov about 7 yearsI watch the changes of table "A" by clicking some other table, and then clicking table "A" again @AlexKost
-
jmartinalonso about 7 yearsFor non-rooted devices this script works : gist.github.com/jk2K/a66ed67b252b880824b32dd4952d1b39
-
Mike6679 about 7 yearsI have large realm db that I only read from. I see the name of it under Web SQL but there are no fields / tables....is it just taking a long time to load?
-
Jemshit Iskenderov about 7 years@Mike6679 not sure, i tried with about 10 tables and maybe 50 rows at most. File a bug on github if you can't see
-
Mike6679 about 7 yearssee this post if anyone has issue with seeing fields: github.com/uPhyca/stetho-realm/issues/45 .... I see my fields but no data....hmmm
-
randy about 7 yearsif you get error like file not found execute adb root command first before pulling realm file .
-
Mike Axle about 7 yearsThis works after using adb root but no matter what I do, the realm file says it's encrypted when using realm browssr. Yes I read about corruption and such but nothing I try is working at all. Did something change in realm?
-
JoshuaTree about 7 yearsAgreed. Since we can set the application to debuggable, we can pull the file with this without root.
-
pratham kesarkar almost 7 yearsThanks. however it's doesn't work with real device.It only works with Emulator
-
Aveek almost 7 years@prathamkesarkar, that is why I have written emulator or rooted device because you cannot get access to these folders in a normal device.
-
EGHDK over 6 yearsCrashing on Android 8.0
-
Gideon Sassoon over 6 yearsProblem with this solution is that if you have a lot of columns it becomes compressed and there's no horizontal scroll
-
Jemshit Iskenderov over 6 years@AkashBisariya i havent tested with latest realm version. but did you click Resources tab? or did you enabled stetho realm plugin in application class?
-
Erum over 6 yearsi can open default.realm but i used this code Realm.init(this); RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("RealmProjectName") .build(); Realm realm = null; try { realm = Realm.getInstance(realmConfiguration); } finally { if (realm != null) { realm.close(); } }i can pull this file but failed to open in Realm Studio.Any idea.unable to find data stored in tables ?
-
Francisco Castro over 6 yearsmac adb default path .../Library/Android/sdk/platform-tools
-
JEGADEESAN S over 6 yearsis there any other way to pull database from non-debuggable apk?
-
JEGADEESAN S over 6 yearsis there any other way to pull database from non-debuggable app and non-rooted mobile?
-
Apperside over 6 yearsif that would be possible, the entire android OS would be completely unsafe, There is a chance it could be possible only on rooted devices, but I never did it
-
SkorpEN about 6 yearsThis might not work on Samsung devices due to their buggy run-as implementations.
-
Aman Verma over 5 yearsMake sure your app is set to debuggable false in order to view the data.
-
krhitesh over 5 years@AmanVerma It's USB debugging in Developer Options. USB debugging must be enabled to use Device File Explorer
-
M.kazem Akhgary over 5 yearsit also works on non-rooted device if the application is debuggable
-
B.shruti over 5 yearsI am testing on Emulator but still my cmd shows remote object '/data/data/<packagename>/files/' does not exist
-
B.shruti over 5 yearsLinux user's can download realm studio using realm.io/products/realm-studio and open realm file from there
-
B.shruti over 5 yearsAnyone who is facing remote object doesn't exist on linux please scroll down and check @Kumar Hitesh answer.
-
Ender about 5 yearsSo, we can use this to import our edited realm back to its place?
adb exec-out run-as package.name cat files/your_database_file_name < your_database_file_name
-
Ender about 5 yearsYou can just use
strings default.realm
to view the file at its location in files/default.realm. -
Maria about 5 yearsThis is the most useful answer, thank you! Does not show the path for macOS, but it is still easy to locate the file.
-
Chris about 5 yearsa working fork is located at github.com/wickedev/stetho-realm. I just set it up and is working on latest realm. Here is from another discussion with updated init example: stackoverflow.com/a/51381971