[英]Flutter - Android doesn't ask for permissions
我正在尝试使用插件位置获取设备的当前位置,但 Android 从不请求权限。 我收到此错误:
发生异常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限永远被拒绝-请打开应用程序设置,null))
我在 Android 文件夹中可以找到的每个“AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪个,我找到了其中的 3 个)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。
我完全迷路了,我在网上找不到类似的东西。 这是代码:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
编辑:我在我的设备(OnePlus 6)和模拟器(Pixel XL API 28)上尝试了这个。 我也尝试卸载/重新安装该应用程序。
我正在尝试使用插件位置获取设备的当前位置,但Android从未要求获得权限。 我收到此错误:
发生异常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限被永久拒绝-请打开应用设置,为null))
我在Android文件夹中可以找到的每个“ AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪一个,我发现了其中的3个)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。
我完全迷路了,网上找不到任何类似的东西。 这是代码:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
编辑:我在我的设备(OnePlus 6)和仿真器(Pixel XL API 28)上尝试了此操作。 我也尝试过卸载/重新安装该应用程序。
我正在尝试使用插件位置获取设备的当前位置,但Android从未要求获得权限。 我收到此错误:
发生异常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限被永久拒绝-请打开应用设置,为null))
我在Android文件夹中可以找到的每个“ AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪一个,我发现了其中的3个)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。
我完全迷路了,网上找不到任何类似的东西。 这是代码:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
编辑:我在我的设备(OnePlus 6)和仿真器(Pixel XL API 28)上尝试了此操作。 我也尝试过卸载/重新安装该应用程序。
我正在尝试使用插件位置获取设备的当前位置,但Android从未要求获得权限。 我收到此错误:
发生异常。 PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限被永久拒绝-请打开应用设置,为null))
我在Android文件夹中可以找到的每个“ AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪一个,我发现了其中的3个)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。
我完全迷路了,网上找不到任何类似的东西。 这是代码:
Future<LocationData> _getLocation() async {
LocationData currentLocation;
// returns a map with unreadable numbers which make no sense
var t = await PermissionHandler()
.requestPermissions([PermissionGroup.location]);
// returns false
var test = await location.requestPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}
编辑:我在我的设备(OnePlus 6)和仿真器(Pixel XL API 28)上尝试了此操作。 我也尝试过卸载/重新安装该应用程序。
添加这个
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.