Data Browser

Last updated 2 months ago

ObjectBox - Data Browser

The ObjectBox data browser (object browser) allows you to

  • view the entities and schema of your database inside a regular web browser,

  • and download entities in JSON format.

The object browser runs directly on your device or on your development machine. Behind the scenes this works by bundling a simple HTTP browser into ObjectBox when building your app. If triggered, it will then provide a basic web interface to the data and schema in your box store.

ObjectBox - Data Brower

Setup

We strongly recommend to use the object browser only for debug builds.

Add the objectbox-android-objectbrowser library to your debug configuration, and the objectbox-android library to your release configuration. Make sure to also apply the “io.objectbox” plugin after the dependencies block:

dependencies {
debugImplementation "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
releaseImplementation "io.objectbox:objectbox-android:$objectboxVersion"
}
// apply the plugin after the dependencies block
apply plugin: 'io.objectbox'

Otherwise the build will fail with a duplicate files error (like Duplicate files copied in APK lib/armeabi-v7a/libobjectbox.so) because the ObjectBox plugin will add the objectbox-android library again.

The objectbox-android-objectbrowser artifact adds required permissions to your AndroidManifest.xml (since version 2.2.0). The permissions added are:

<!-- Required to provide the web interface -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Required to run keep-alive service when targeting API 28 or higher -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

If you only use the browser library for debug builds as recommended above, they will not be added to your release build.

After creating your BoxStore, start the object browser using an AndroidObjectBrowser instance. Typically in the onCreate() method of your Application class:

boxStore = MyObjectBox.builder().androidContext(this).build();
if (BuildConfig.DEBUG) {
boolean started = new AndroidObjectBrowser(boxStore).start(this);
Log.i("ObjectBrowser", "Started: " + started);
}

Browse data on your device

When the app starts an object browser notification should appear. Tapping it will launch a service to keep the app alive and opens the data browser interface in the web browser on the device.

To stop the service keeping your app alive, tap the ‘Stop’ button in the notification.

Browse data on your dev machine

To open the browser website on your development machine check the Logcat output when launching the app. It will print the port and the ADB command needed to forward the port to your machine:

I/ObjectBrowser: ObjectBrowser started: http://localhost:8090/index.html
I/ObjectBrowser: Command to forward ObjectBrowser to connected host: adb forward tcp:8090 tcp:8090

If available, port 8090 is used by default. So in most cases just run this command on your dev machine:

adb forward tcp:8090 tcp:8090

Once the port is forwarded you can open a browser and go to http://localhost:8090/index.html.

Download entities

When viewing entities tap the download button at the very bottom. This will download entities formatted as JSON.

Download entities