如何使用现有的Realm作为资源

时间:2018-02-02 18:33:53

标签: android realm

我想把已经有一些数据的Realm数据库放到Android的assets文件夹中作为只读资源文件,我该怎么办?

1 个答案:

答案 0 :(得分:2)

根据https://realm.io/docs/java/latest/#read-only-realms

您可以将 For Each row As DataGridViewRow In DataGridView1.Rows Dim pn As String = row.Cells(1).Value.ToString Dim des As String = row.Cells(2).Value.ToString Dim quan As String = row.Cells(3).Value.ToString Dim pcs As String = ("PCS") Dim pri As String = row.Cells(4).Value.ToString Dim total As String = row.Cells(5).Value.ToString Dim x1 As String = 10 Dim y1 As String = 185 Dim z1 As String = (" ") Dim x2 As String = 60 Dim y2 As String = 200 Dim z2 As String = (" ") Dim z4 As String = (" ") Dim z5 As String = (" ") e.Graphics.DrawString(pn + z1 + des, Me.Font, Brushes.Black, x1, y1) e.Graphics.DrawString(quan + z4 + pcs + z2 + pri + z5 + total, Me.Font, Brushes.Black, x2, y2) Next 文件放入the_realm.realm文件夹

然后你可以构建一个配置(使其成为/assets),如此

readOnly()

然后RealmConfiguration config = new RealmConfiguration.Builder() .assetFile("the_realm.realm") .readOnly() // It is optional, but recommended to create a module that describes the classes // found in your bundled file. Otherwise if your app contains other classes // than those found in the file, it will crash when opening the Realm as the // schema cannot be updated in read-only mode. .modules(new BundledRealmModule()) .build(); 就像

BundledRealmModule