Flutter:请求用户许可,直到获得许可

发布于 2025-01-09 18:49:01 字数 210 浏览 5 评论 0原文

使用 https://pub.dev/packages/permission_handler 获取权限

,但不会询问用户如果用户拒绝许可,则再次执行。

目前在 android 上检查过(iOS 设备不可用)

请帮助

Using https://pub.dev/packages/permission_handler to get permissions

but it won't ask the user again if user denied permission.

currently checked it on android (iOS device is not available)

Pls Help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痕至 2025-01-16 18:49:01

如果用户已经拒绝,唯一可以做的就是将用户重定向到应用程序设置以启用所需的权限。

if (await Permission.speech.isPermanentlyDenied) {
  // The user opted to never again see the permission request dialog for this
  // app. The only way to change the permission's status now is to let the
  // user manually enable it in the system settings.
  openAppSettings();
}

If a user has already denied, only thing could be done is to redirect the user to application settings to enable needed permissions.

if (await Permission.speech.isPermanentlyDenied) {
  // The user opted to never again see the permission request dialog for this
  // app. The only way to change the permission's status now is to let the
  // user manually enable it in the system settings.
  openAppSettings();
}
梦巷 2025-01-16 18:49:01

据我了解,如果被拒绝,您希望不断请求用户许可。
您可以实现类似的方法来不断请求请求,除非您收到拒绝之外的其他信息:

 Future<bool> askPermission() async{
    PermissionStatus status = await Permission.contacts.request();
    if(status.isDenied == true)
      {
        askPermission();
      }
    else
      {
        return true;
      }
  }

无论您在哪里请求权限,都可以调用此类方法。

As i understood you want to continuously ask user for permission if it is denied.
You can implement something like this to continuously ask for the request unless you get something other than denied :

 Future<bool> askPermission() async{
    PermissionStatus status = await Permission.contacts.request();
    if(status.isDenied == true)
      {
        askPermission();
      }
    else
      {
        return true;
      }
  }

Call this type of method wherever you are requesting for the permission.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文