Kin*_*ore 4 android apk android-assets
我有一个使用v1.0的应用程序,该应用程序使用保存在资产文件夹中的本地数据库...我已将我的应用程序更新为1.1版,在新版本中,内部数据库具有不同的条目。
不幸的是,已安装的应用程序继续使用1.0版的数据库,我必须取消安装该应用程序,然后再次安装才能使用最新版本的数据库。
真的是一件坏事,迫使购买者取消安装应用程序并重新安装新版本...为什么资产文件未使用新版本更新?
编辑
我知道发生此问题是因为数据库是从资产文件创建的,并且只有在尚未创建的情况下,这才是我的DatabaseHelper类
public class DataBaseHelper extends SQLiteOpenHelper {
private static String TAG = "DataBaseHelper";
private static String DB_PATH = "";
private static String DB_NAME = "MyDatabaseFile";
private SQLiteDatabase mDataBase;
private final Context mContext;
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, 1);
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
this.mContext = context;
}
public void createDataBase() throws IOException {
// If database not exists copy it from the assets
boolean mDataBaseExist = checkDataBase();
if (!mDataBaseExist) {
this.getReadableDatabase();
this.close();
try {
copyDataBase();
Log.e(TAG, "createDatabase database created");
} catch (IOException mIOException) {
throw new Error("ErrorCopyingDataBase");
}
}
}
private boolean checkDataBase() {
File dbFile = new File(DB_PATH + DB_NAME);
// Log.v("dbFile", dbFile + " "+ dbFile.exists());
return dbFile.exists();
}
private void copyDataBase() throws IOException {
InputStream mInput = mContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
public boolean openDataBase() throws SQLException {
String mPath = DB_PATH + DB_NAME;
// Log.v("mPath", mPath);
mDataBase = SQLiteDatabase.openDatabase(mPath, null,
SQLiteDatabase.CREATE_IF_NECESSARY);
// mDataBase = SQLiteDatabase.openDatabase(mPath, null,
// SQLiteDatabase.NO_LOCALIZED_COLLATORS);
return mDataBase != null;
}
@Override
public synchronized void close() {
if (mDataBase != null)
mDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase arg0) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
当我在PlayStore上升级应用程序而不重命名db文件时,如何避免此问题?
我有一个应用程序v1.0,该应用程序使用保存在资产文件夹中的本地数据库
不,您有一个应用程序v1.0,可以复制 “保存在资产文件夹中”的数据库并从中创建本地数据库。希望您SQLiteAssetHelper为此使用。
为什么资产文件没有用新版本更新?
资产文件已更新。您没有做任何事情来修复您制作的副本。如果使用SQLiteAssetHelper,它具有处理此类升级的过程。
| 归档时间: |
|
| 查看次数: |
2501 次 |
| 最近记录: |