我在我的应用程序资产文件夹中保存了一个数据库,并在应用程序首次打开时使用以下代码复制数据库。
inputStream = mContext.getAssets().open(Utils.getDatabaseName());
if(inputStream != null) {
int mFileLength = inputStream.available();
String filePath = mContext.getDatabasePath(Utils.getDatabaseName()).getAbsolutePath();
// Save the downloaded file
output = new FileOutputStream(filePath);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = inputStream.read(data)) != -1) {
total += count;
if(mFileLength != -1) {
// Publish the progress
publishProgress((int) (total * 100 / mFileLength));
}
output.write(data, 0, count);
}
return true;
}
上面的代码运行没有问题,但是当您尝试查询数据库时,您会得到一个 SQLite: No such table 异常。
此问题仅在 Android P 中出现,所有早期版本的 Android 都可以正常工作。
这是 Android P 的一个已知问题还是发生了一些变化?