我需要Realm在android 中的数据库中添加自动增量键字段.我怎样才能做到这一点?这可能吗?
提前致谢.
我从以下链接https://github.com/realm/realm-java/tree/master/examples/encryptionExample/src/main/java/io/realm/examples/encryptionexample创建了Realm Encryption Example项目源.当我运行时项目没有任何代码更改,它运行没有错误.但我在源代码中注释以下行
Realm.deleteRealm(realmConfiguration);
Run Code Online (Sandbox Code Playgroud)
因为我不需要删除旧文件.然后我启动application.it抛出错误java.lang.IllegalArgumentException:非法参数:领域文件的格式无效.
如何使用相同的加密密钥读取Realm文件.
源代码:
package io.realm.examples.encryptionexample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import java.security.SecureRandom;
import io.realm.Realm;
import io.realm.RealmConfiguration;
public class EncryptionExampleActivity extends Activity {
public static final String TAG = EncryptionExampleActivity.class.getName();
private Realm realm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Generate a key
// IMPORTANT! This is a silly way to generate a key. It is also never stored.
// For proper key handling please consult:
// * https://developer.android.com/training/articles/keystore.html
// * http://nelenkov.blogspot.dk/2012/05/storing-application-secrets-in-androids.html
byte[] …Run Code Online (Sandbox Code Playgroud)