Realm Browser

Recently realm released realm 0.86 that included Dynamic Realms. With Dynamic Realms we can have access to Realm Schema and we can also create objects and access fields dynamically with using strings (Model name and Field name respectively). These flexibility of Dynamic Realms gave me idea to create a Realm Browser for Android.

Concept

Realm browser that can be used to see tables, structure and content. This browser can be accessed from localhost that hosted by the Android device. To achieve that I’m using NanoHTTPD library.

NanoHTTP

NanoHTTPD is a light-weight HTTP server designed for embedding in other applications, released under a Modified BSD licence.

This simple code will create a HTML page with Hello server text that can be accessed from localhost with port 8080.

DynamicRealm

Like I said in the beginning, Dynamic Realms are flexible version of Conventional Realm. Dynamic Realms are opened using the same configuration you use for the conventional Realms, but they ignore any schema, migration, and schema version.

With Dynamic Realms you can access contents as long as you know model name and field name

Currently there is no API to get field types but I already filled an issue and the fix will be released in next version (0.87).
So currently I’m using a workaround to get field types with manually checking Object types

Usage

To use this library you can create an instance of RealmBrowser and then call RealmBrowser.start(); you can also set the port if you want. Don’t forget to call RealmBrowser.stop(); after you finished.

To access RealmBrowser from your browser your Android device and PC/Mac need to be on the same network. And then you can call realmBrowser.showServerAddress(this); to show the address in logcat.

Download

You can get the full source code in my github or you can get it via gradle

compile 'com.nikoyuwono:realm-browser:0.1'

Ending Words

This library still need a lot of improvement, I’m planning to adding search function this week and will also thinking about better approach to create the webpage. Currently the full code is available in github, any feedbacks, issues or pull requests would be greatly appreciated.