我从资产中复制DB代码:
public class DatabaseHelper extends OrmLitesqliteOpenHelper { private static final String DATABASE_NAME = "database.db"; private static final String DATABASE_PATH = "/data/data/"+BuildConfig.APPLICATION_ID+"/databases/"; public DatabaseHelper(Context context) { super(context,DATABASE_NAME,null,DATABASE_VERSION); copyFromAssets(context); } private void copyFromAssets(Context context) { boolean dbexist = checkdatabase(); if (!dbexist) { File dir = new File(DATABASE_PATH); dir.mkdirs(); InputStream myinput = context.getAssets().open(DATABASE_NAME); String outfilename = DATABASE_PATH + DATABASE_NAME; Log.i(DatabaseHelper.class.getName(),"DB Path : " + outfilename); OutputStream myoutput = new FileOutputStream(outfilename); byte[] buffer = new byte[1024]; int length; while ((length = myinput.read(buffer)) > 0) { myoutput.write(buffer,length); } myoutput.flush(); myoutput.close(); myinput.close(); } } }
得到Dao我用这个:
public Dao<AnyItem,Integer> getDaoAnyItem() throws sqlException { if (daoAnyItem == null) { daoAnyItem = getDao(AnyItem.class); } return daoAnyItem; }
但是如何获取Dao如果我的DB将被密码保护?
解决方法
您必须使用OrLCite的sqlCipher,我会向您推荐
ormlite-sqlcipher库