作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我用 flutter 创建了一个 android 应用程序,我在应用程序运行时第一次创建权限请求,所以当用户单击拒绝然后单击登录按钮时,再次请求权限。我遇到了这个错误
Exception has occurred.
PlatformException (PlatformException(ERROR_ALREADY_REQUESTING_PERMISSIONS, A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)., null))
这是我的代码
@override
void initState() {
this.setSharedPreferences();
PermissionHandler().checkPermissionStatus(PermissionGroup.location).then(_checkPermission);
}
void _checkPermission(PermissionStatus status){
if(status == PermissionStatus.unknown || status == PermissionStatus.denied){
_askPermission();
}
}
void _askPermission() async{
await PermissionHandler().requestPermissions([PermissionGroup.location]);
}
void onLogin() async {
PermissionStatus locationPermission = await PermissionHandler().checkPermissionStatus(PermissionGroup.location);
if(locationPermission == PermissionStatus.denied || locationPermission == PermissionStatus.unknown){
_askPermission();
}else{
// user available to login
}
}
如何处理?谢谢你的回答
最佳答案
事情是当它检查权限时它返回 null 而不是任何权限状态,这会导致异常。这可能是一个错误,很多人已经解决了与位置权限相关的问题。
https://github.com/BaseflowIT/flutter-geolocator/issues/172
https://github.com/BaseflowIT/flutter-geolocator/issues/
https://github.com/BaseflowIT/flutter-permission-handler/issues
void getPermissionStatus() async {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.storage);
if (permission == PermissionStatus.granted) {
} // ideally you should specify another condition if permissions is denied
else if (permission == PermissionStatus.denied ||
permission == PermissionStatus.disabled ||
permission == PermissionStatus.restricted) {
await PermissionHandler().requestPermissions([PermissionGroup.storage]);
getPermissionStatus();
}
}
我不认为你的代码有问题,无论如何你可以使用递归而不是创建两个单独的函数。
关于android - ERROR_ALREADY_REQUESTING_PERMISSIONS flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56069917/
我用 flutter 创建了一个 android 应用程序,我在应用程序运行时第一次创建权限请求,所以当用户单击拒绝然后单击登录按钮时,再次请求权限。我遇到了这个错误 Exception has oc
我是一名优秀的程序员,十分优秀!