我想知道如何在Flutter中打开特定应用程序的权限设置?我在互联网上搜索,但没有一篇文章向我展示如何操作,只有一些针对Android的解决方案,例如打开应用程序权限设置。
嗨,尝试使用 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();
谢谢
@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.');
}
openAppSettings();
时,将执行本地代码,而不是此实现:throw UnimplementedError('openAppSettings() has not been implemented.');
- sitatech