为了克服这个问题,您可以在手机的 SD 卡中创建您的数据库。它工作顺利,用户也可以访问。如果涉及安全性,则使用 res/raw 文件夹,以便用户无法访问它。要在 SD 卡上创建数据库,您可以使用以下代码(它是示例代码)...
public static void saveExpanseForm(Context con,NewExpenseForm newexpanse) throws Exception {
SQLiteDatabase sampleDB = null;
try {
File sdcard;
if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)){
sdcard = new File(Environment.getExternalStorageDirectory(), "ROIApp");
sdcard.mkdirs();
} else {
/* save the folder in internal memory of phone */
sdcard = new File(Environment.getRootDirectory(),"ROIApp");
sdcard.mkdirs();
}
String dbfile = sdcard.getAbsolutePath() + File.separator+ "RoiAppDB" + File.separator + NETNOTENABLE_DB_NAME;
sampleDB = con.openOrCreateDatabase(dbfile, MODE_PRIVATE,null);
sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " + Expense_TABLE_NAME +
" (id INTEGER PRIMARY KEY AUTOINCREMENT, Currentdate varchar, dateFormat varchar, Name varchar, Category varchar,"+
" Location varchar,Cost varchar,Sex INTEGER, Tags varchar, Notes varchar, In1 varchar, In2 varchar, " +
"Remindme INTEGER, ImagePath varchar);");
sampleDB.execSQL("INSERT INTO " + Expense_TABLE_NAME +
"(Currentdate, dateFormat, Name, Category, Location,Cost, Sex, Tags, Notes, In1, In2, Remindme, ImagePath ) Values ('"
+newexpanse.getDates()+"','"+newexpanse.getDateFormat()+"','"+newexpanse.getName()+"','"+
newexpanse.getCategory()+"','"+newexpanse.getLocation()+"','"+newexpanse.getCost()+"','"+newexpanse.getSex()+"','"+newexpanse.getTag()+"','"
+newexpanse.getNotes()+"','"+newexpanse.getInstr1()+"','"+newexpanse.getInstr2()+"','"
+newexpanse.getRemindme()+"','"+newexpanse.getImageName()+"');");
Log.e("ExpanseTable", " ExpanseInsert "+"INSERT INTO " + Expense_TABLE_NAME +
"(Currentdate, dateFormat, Name, Category, Location,Cost, Sex, Tags, Notes, In1, In2, Remindme,ImagePath ) Values ('"
+newexpanse.getDates()+"','"+newexpanse.getDateFormat()+"','"+newexpanse.getName()+"','"+
newexpanse.getCategory()+"','"+newexpanse.getLocation()+"','"+newexpanse.getCost()+"','"+newexpanse.getSex()+"','"+newexpanse.getTag()+"','"
+newexpanse.getNotes()+"','"+newexpanse.getInstr1()+"','"+newexpanse.getInstr2()+"','"
+newexpanse.getRemindme()+"','"+newexpanse.getImageName()+"');");
insertNewExpanseForm(sampleDB);
} catch (SQLiteException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
if (sampleDB != null)
sampleDB.close();
}
}