android - GetCurrentLocation 在调试中工作,但在 Android 的发布 apk 中不起作用
问题描述
我遇到了 geolocator 包的问题,当我在调试模式下运行我的应用程序时,一切正常,但是当我构建应用程序并使用发布模式时,它卡在了我的加载屏幕中,其中有来自 geolocator 包的 getcurrentlocation。
Future<void> getCurrentLocation() async {
try {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
Position position = await geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
);
latitude = position.latitude;
longitude = position.longitude;
} catch (e) {
print(e);
}
}
并添加到 android 清单访问。
解决方案
对于我的情况,我发现我必须在 AndroidManifest 中添加互联网权限。xml
<uses-permission android:name="android.permission.INTERNET" />
推荐阅读
- .net - 在 Visual Studio for Mac 上进行单声道更新后的框架不匹配
- c# - 单屏按按键几个版本
- java - 在Android中如何检查设备是否有前置闪光灯(Camera2 API)
- sql-server - SQL Server Management Studio 64位安装问题
- hadoop - 在 impala 数据库名称中使用连字符
- mongodb - 在聚合管道的 $project 中形成的字典顺序,在 pymongo 中获取时发生变化
- python - 将未对齐的值移动到给定的列
- android - 创建反应原生自定义标题样式?
- javascript - 如何将道具传递给材质 UI 样式的组件?
- batch-file - 在批处理文件中创建具有复杂路径目标的快捷方式文件