file is encrypted or is not a database (Exception net.sqlcipher.database.SQLiteException)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 10:33:12
CommonsWare

since my old db is not encrypted so what should i set password in that case

SQLCipher for Android can open an unencrypted database using "" as the password.

i have tried with passing null in password string and also with "" but no luck

Then either:

  • You have a bug in your code, or
  • The database is already encrypted with another password, or
  • The database is corrupted.
  1. check if you're using the right import: import net.sqlcipher.database.SQLiteDatabase;

  2. load libs on start of the app like this:

SQLiteDatabase.loadLibs(this); //this = activity (usually a SplashScreen or MainActivity)
db = DatabaseHandler.getInstance(this); //if it's singleton (and i suggest making it as such)
db.getReadableDatabase(ConstantsHandler.DATABASE_PASSWORD);
db.close();
  1. make sure it's not already encrypted with a password

  2. check File permissions:

< uses-permission> android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

< uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!