首页 > 解决方案 > 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 数据库目录?

标签: fileflutterdart

解决方案


推荐阅读