问题
How to move my Realm file in SD card?
And not just move, but also to connect to my application?
回答1:
Realm also has constructors for opening any file: http://realm.io/docs/java/0.80.0/api/io/realm/Realm.html#getInstance-java.io.File-java.lang.String-
So something like this should work:
Realm realm = Realm.getInstance(Environment.getExternalStorageDirectory());
And remember to add this to your manifest:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
...
</manifest>
Also not all phones has a SD card and it might not be mounted so you will need additional checks for that if you don't want to encounter lots of weird crashes in production: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
来源:https://stackoverflow.com/questions/29551664/how-to-move-my-realm-file-in-sd-card