简体   繁体   English

"Flutter - Android 不请求权限"

[英]Flutter - Android doesn't ask for permissions

I'm trying to get the current location of the device using the plugin location but Android never asks for permissions.我正在尝试使用插件位置获取设备的当前位置,但 Android 从不请求权限。 I get this error:我收到此错误:

Exception has occurred.发生异常。 PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, null)) PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限永远被拒绝-请打开应用程序设置,null))

I have added the line below in every `AndroidManifest.xml´ file that I could find in the Android folder (no idea which one I should use actually, I found 3 of them)我在 Android 文件夹中可以找到的每个“AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪个,我找到了其中的 3 个)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

I tried the plugin permission_handler to request them manually but still, no pop-up.我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。

I'm completely lost and I find nothing similar on the net.我完全迷路了,我在网上找不到类似的东西。 Here is the code :这是代码:

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;
}

Edit: I tried this on my device (OnePlus 6) and on an emulator (Pixel XL API 28).编辑:我在我的设备(OnePlus 6)和模拟器(Pixel XL API 28)上尝试了这个。 I've also tried to uninstall/reinstall the app.我也尝试卸载/重新安装该应用程序。

I'm trying to get the current location of the device using the plugin location but Android never asks for permissions.我正在尝试使用插件位置获取设备的当前位置,但Android从未要求获得权限。 I get this error:我收到此错误:

Exception has occurred.发生异常。 PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, null)) PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限被永久拒绝-请打开应用设置,为null))

I have added the line below in every `AndroidManifest.xml´ file that I could find in the Android folder (no idea which one I should use actually, I found 3 of them)我在Android文件夹中可以找到的每个“ AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪一个,我发现了其中的3个)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

I tried the plugin permission_handler to request them manually but still, no pop-up.我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。

I'm completely lost and I find nothing similar on the net.我完全迷路了,网上找不到任何类似的东西。 Here is the code :这是代码:

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;
}

Edit: I tried this on my device (OnePlus 6) and on an emulator (Pixel XL API 28).编辑:我在我的设备(OnePlus 6)和仿真器(Pixel XL API 28)上尝试了此操作。 I've also tried to uninstall/reinstall the app.我也尝试过卸载/重新安装该应用程序。

I'm trying to get the current location of the device using the plugin location but Android never asks for permissions.我正在尝试使用插件位置获取设备的当前位置,但Android从未要求获得权限。 I get this error:我收到此错误:

Exception has occurred.发生异常。 PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, null)) PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限被永久拒绝-请打开应用设置,为null))

I have added the line below in every `AndroidManifest.xml´ file that I could find in the Android folder (no idea which one I should use actually, I found 3 of them)我在Android文件夹中可以找到的每个“ AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪一个,我发现了其中的3个)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

I tried the plugin permission_handler to request them manually but still, no pop-up.我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。

I'm completely lost and I find nothing similar on the net.我完全迷路了,网上找不到任何类似的东西。 Here is the code :这是代码:

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;
}

Edit: I tried this on my device (OnePlus 6) and on an emulator (Pixel XL API 28).编辑:我在我的设备(OnePlus 6)和仿真器(Pixel XL API 28)上尝试了此操作。 I've also tried to uninstall/reinstall the app.我也尝试过卸载/重新安装该应用程序。

I'm trying to get the current location of the device using the plugin location but Android never asks for permissions.我正在尝试使用插件位置获取设备的当前位置,但Android从未要求获得权限。 I get this error:我收到此错误:

Exception has occurred.发生异常。 PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, null)) PlatformException(PlatformException(PERMISSION_DENIED_NEVER_ASK,位置权限被永久拒绝-请打开应用设置,为null))

I have added the line below in every `AndroidManifest.xml´ file that I could find in the Android folder (no idea which one I should use actually, I found 3 of them)我在Android文件夹中可以找到的每个“ AndroidManifest.xml”文件中添加了以下行(不知道我应该实际使用哪一个,我发现了其中的3个)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

I tried the plugin permission_handler to request them manually but still, no pop-up.我尝试了插件permission_handler手动请求它们,但仍然没有弹出窗口。

I'm completely lost and I find nothing similar on the net.我完全迷路了,网上找不到任何类似的东西。 Here is the code :这是代码:

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;
}

Edit: I tried this on my device (OnePlus 6) and on an emulator (Pixel XL API 28).编辑:我在我的设备(OnePlus 6)和仿真器(Pixel XL API 28)上尝试了此操作。 I've also tried to uninstall/reinstall the app.我也尝试过卸载/重新安装该应用程序。

add this添加这个

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM