简体   繁体   English

如何在SD卡中移动Realm文件?

[英]How to move my Realm file in SD card?

How to move my Realm file in SD card? 如何在SD卡中移动Realm文件?

And not just move, but also to connect to my application? 不仅可以移动,还可以连接到我的应用程序?

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- Realm还具有用于打开任何文件的构造函数: 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 同样,并非所有手机都具有SD卡,因此可能未安装,因此如果您不想在生产中遇到很多奇怪的崩溃,就需要进行其他检查: http : //developer.android.com/guide/topics /data/data-storage.html#filesExternal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM