我在使用某些设备时遇到崩溃问题SQLite资产助手 https://github.com/jgilfelt/android-sqlite-asset-helper在我的应用程序中,主要是在 OnePlus 设备上。现在我读了here https://stackoverflow.com/questions/32697235/database-not-getting-copied-properly-in-oneplus-two#comment55802445_32697235它与数据库存储的目录有关。
现在我正在尝试找到一种解决方法,目前我能想到的最好的方法就是像这样的构造函数
public MySubclass(Context context) {
super(context, databaseName, context.getFilesDir() + "/databases", null, databaseVersion);
这是正确的方法还是这种方法还有其他问题?
EDIT
例外的是
Fatal Exception: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version x to y: /data/data/my.package.id/databases/database.db
抱歉,我链接了错误的SO问题:这是正确的 https://stackoverflow.com/questions/32797784/unable-to-use-external-database-in-android-app。那里说“OnePlus 能够将数据库复制到 /data/data/package-name/databases/filename.db 但它不允许访问该数据,我对此一无所知。”
SQLiteAssetHelper 构造函数允许您指定自己的数据库目标路径(该文件夹需要可写)。如果您不指定任何一个,则默认使用一个。请参阅 Github 存储库的摘录:
if (storageDirectory != null) {
mDatabasePath = storageDirectory;
} else {
mDatabasePath = context.getApplicationInfo().dataDir + "/databases";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)