android - Flutter - Android 不请求权限

标签 android flutter permissions

我正在尝试使用插件 location 获取设备的当前位置但 Android 从不要求权限。我收到此错误:

Exception has occurred. PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, 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) 上试过这个。我也尝试过卸载/重新安装该应用程序。

最佳答案

location plugin 的 git 上询问之后,我这样做了:

flutter clean

我收到了请求权限的弹出窗口。

感谢this guy .

关于android - Flutter - Android 不请求权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55659267/

相关文章:

list - 从列表中更改 containerColor

python - open() 的 I/O 错误

android - 如何在 Hook android(使用 xposed)时获取返回值?

android - Windows 10 升级后 Genymotion 错误

flutter - 在 onTap ( Flutter ListItem ) 中执行函数后如何更改图标的颜色

dart - Stack 子部件的动态部件高度

android - 如何在安装或删除其他应用程序时让我的应用程序接收广播

c# - 当 requestedExecutionLevel 设置为 "requireAdministrator"时,windows 8 winform 不会自动启动

java - Android 文件转字符串

android - 已检查可空性时的 Kotlin 空值检查(!!)