我已经连接了我的计算机上的真实的设备,当我运行flutter run --release --verbose
一切工作正常,但当我运行flutter build apk
并安装apk,应用程序启动,但似乎没有下载文件
await Dio().download(fileurl, savePath);
或无法读取它(我不知道,因为我没有从apk日志,无法使用getApplicationDocumentsDirectory检查文件下载与非根真实的设备)
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<File> get _localFile async {
final path = await _localPath;
return File('$path/file.gpx');
}
_readGPX() async {
print("_readGPX");
final myTransformer = Xml2Json();
try {
final file = await _localFile;
final goodXmlString = await file.readAsString();
myTransformer.parse(goodXmlString);
var jsondata = myTransformer.toParkerWithAttrs();
setState(() {
_trkpt = jsonDecode(jsondata)['gpx']['trk']['trkseg']['trkpt'];
if (_trkpt != null) {
setState(() {
_gpxLoaded = true;
});
}
});
} catch (e) {
return 0;
}
}
1条答案
按热度按时间w80xi6nr1#
感谢哈迪克· meta
在清单中添加
<uses-permission android:name="android.permission.INTERNET" />