file - File.writeAsbytes() 在 Android 4.4.4 Kitkat 上不起作用
问题描述
我的应用程序需要一个预制的 sqlite 数据库文件,该文件位于我的颤振资产中。当我尝试将其复制到应用程序的数据库目录时,它不起作用。它适用于 Android API 级别 28 和 29,但不适用于 Api 19 (Kitkat)。
String path = Path.join(await getDatabasesPath(), 'audio.db');
if (FileSystemEntity.typeSync(path) == FileSystemEntityType.notFound) {
ByteData data = await rootBundle.load(Path.join('assets', 'audio.db'));
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
//reaches here
await new File(path).writeAsBytes(bytes).then((file) {
print('copied audio');//doesn't print
});
} //stucks here
return true; //never returns
}
我也尝试了 writeAsBytesSync 方法,但都不起作用。有没有其他方法可以将我的 db 文件复制到 app 数据库目录?
解决方案
推荐阅读
- computer-science - 键盘的作用是什么?
- node.js - 我该如何解决nodemon不断显示的这个错误
- javascript - 如何承诺 Cordova File 插件?
- google-apps-script - 单元格引用超出范围 - 但我使用 GetDataRange()
- c++ - 如何在 C++ 中使用客户区的 HTML/CSS UI 制作本机 UI 窗口
- pandas - groupby 后基于另一列中的值的条件总和
- app-store - 通过 API 或接口直接向 JIRA 提交 App Store Connect Tester 反馈
- jquery - 最大输出号码选择器
- java - 无法调试 Spring Boot 应用程序 jar
- c# - 500 - 在服务器上发布后内部服务器错误