Anda dapat mengakses file ranah secara langsung. Inilah solusi yang saya gunakan.
Pertama, Anda dapat menyalin file ranah yang terletak di '/ data / data / nama paket / file' ke 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);
}
in.close();
out.close();
}
}
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) {
e.printStackTrace();
}
}
}
finally {
if (realm != null)
realm.close();
}
Kedua, gunakan alat ADB untuk menarik file itu seperti ini:
$ adb pull /sdcard/default.realm.
Sekarang Anda dapat membuka file di Realm Browser.