打开特定应用程序的权限设置(Flutter)?

11

我想知道如何在Flutter中打开特定应用程序的权限设置?我在互联网上搜索,但没有一篇文章向我展示如何操作,只有一些针对Android的解决方案,例如打开应用程序权限设置

2个回答

22

嗨,尝试使用 permission_handler(https://pub.dev/packages/permission_handler) 包的帮助来请求权限和打开应用程序设置,例如定位。

Future<void> _request_permission(context,Function fn)async{
    final Permission location_permission=Permission.location;
    bool location_status=false;
    bool ispermanetelydenied= await location_permission.isPermanentlyDenied;
    if(ispermanetelydenied) {
      print("denied");
      await  openAppSettings();
    }else{
      var location_statu = await location_permission.request();
      location_status=location_statu.isGranted;
      print(location_status);
    }
 
  }

这个函数可以让您在用户永久拒绝权限的情况下打开应用程序设置并管理权限。

openAppSettings();

谢谢


-2

@azad-prajapat 当我查看包代码时,我发现了这个

/// Opens the app settings page.
  ///
  /// Returns [true] if the app settings page could be opened, otherwise
  /// [false].
  Future<bool> openAppSettings() {
    throw UnimplementedError('openAppSettings() has not been implemented.');
  }

你的回答可以通过添加更多的支持信息来改进。请编辑添加更多细节,例如引用或文献资料,以便其他人可以确认您的答案是否正确。您可以在帮助中心找到有关如何编写良好答案的更多信息。 - Community
2
这是正常的,因为在Flutter中不可能直接打开应用程序设置,而必须在本地代码中完成。基本上,当您调用openAppSettings();时,将执行本地代码,而不是此实现:throw UnimplementedError('openAppSettings() has not been implemented.'); - sitatech

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接