我正在尝试从用户那里获取存储权限。下面是示例(复制-粘贴)代码。但是当我试图请求许可时出现了错误。
D/permissions_handler(12775): No permissions found in manifest for: []22
代码
import 'package:duplicate_file_remover/globals.dart' as globals;
import 'package:duplicate_file_remover/ui/views/homeViews/homeView.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:permission_handler/permission_handler.dart';
class MainDataProvider extends StatefulWidget {
const MainDataProvider({Key? key}) : super(key: key);
@override
_MainDataProviderState createState() => _MainDataProviderState();
}
class _MainDataProviderState extends State<MainDataProvider> {
PermissionStatus _permissionStatus = PermissionStatus.denied;
Future<void> _askStoragePermission() async {
debugPrint(" ---------------- Asking for permission...");
await Permission.manageExternalStorage.request();
if (await Permission.manageExternalStorage.request().isGranted) {
PermissionStatus permissionStatus =
await Permission.manageExternalStorage.status;
setState(() {
_permissionStatus = permissionStatus;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
onPressed: () async {
await _askStoragePermission();
if (_permissionStatus.isGranted) {
debugPrint(" ---------------- Permission allowed");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeView(),
),
);
} else {
// openAppSettings();
debugPrint(" --------------------- Permission denied");
}
},
child: const Text("Get permission"),
),
),
);
}
}
我使用的是permission_handler
(https://pub.dev/packages/permission_handler)包。
我试过this solutions,但它不工作。
4条答案
按热度按时间pxq42qpu1#
在
build.gradle
文件中检查targetSdkVersion
。如果您使用的是Android 11(targetSdkVersion = 30),则需要以不同的方式将此权限写入
manifest
。您可以尝试this post中讨论的解决方案brjng4g32#
对于那些有经验的人来说,
将此权限添加到清单文件中的<清单标签下
rks48beu3#
我有同样的错误,我解决了它,通过创建一个新的Flutter项目,并复制我的代码到新的
slwdgvem4#