我有一个数据库保存在我的应用程序资产文件夹中,并在应用程序首次打开时使用以下代码复制数据库.
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;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码运行没有问题,但是当你尝试查询数据库时,你会得到一个SQLite:没有这样的表异常.
此问题仅发生在Android P中,所有早期版本的Android都能正常工作.
这是Android P的已知问题还是有些变化?