Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm data browser on Windows 10

Tags:

realm

I manage to get export.realm using those code

package com.meow.meowmeow;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import io.realm.Realm;
import io.realm.RealmConfiguration;

/**
 * Created by Thien on 9/1/2015.
 */
public class RealmTool {
    private static String LOG_TAG = "RealmTool";

    //export to email
    public static void exportDatabase(Context context,RealmConfiguration configuration) {

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

        File exportRealmFile = null;
        try {
            // get or create an "export.realm" file
            exportRealmFile = new File(context.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
        context.startActivity(Intent.createChooser(intent, "YOUR CHOOSER TITLE"));
    }

    //import from assets
    public static RealmConfiguration importDatabase(Context context, String realm_file_name){
        RealmConfiguration defaultRealm = new RealmConfiguration.Builder(context).build();
        String dir = defaultRealm.getPath();
        AssetManager assetManager = context.getAssets();
        try {
            InputStream is;
            is = assetManager.open(realm_file_name);
            File dest = new File(dir);
            if (dest.exists())
                dest.delete();
            copy(is,dest);
        }catch (IOException e){
            Log.e(LOG_TAG,"import database error");
        }
        return defaultRealm;
    }

    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);
        }
        in.close();
        out.close();
    }
    public static void copy(InputStream in, File dst) throws IOException {

        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);
        }
        in.close();
        out.close();
    }

}

Now I want to check it out. How to edit it in windows. The developer said they only has realm browser on Mac But I am using windows 10. So anyone have any ways or any tool to browser realm on Windows. Thank you.

like image 836
Haha TTpro Avatar asked Sep 03 '15 05:09

Haha TTpro


1 Answers

(Disclaimer: I'm the guy in charge of Realm Browser for Mac. :) )

We hear you! Unfortunately, at the moment, to even consider a version of Realm Browser for Windows, we need to get Realm itself running on Windows to begin with! It's something we're absolutely working on, but obviously it's not a small amount of work; so we haven't got any release timelines yet.

For the time being, if you want to debug a Realm file from an Android app, there's actually a really cool open-source third party Android Realm browser app that you could potentially use instead: https://github.com/dmytrodanylyk/realm-browser

Sorry I couldn't bring any better news, but at the very least, I hope that helps in the interim. But we're 100% aware that having an equivalent version of Realm Browser on Windows would greatly help Android development on that platform.

like image 106
TiM Avatar answered Jan 16 '23 15:01

TiM