6

I'm trying to get storage permission from the user. Below is the sample (copy-paste) code. But I'm getting error when I'm trying to request the permission.

D/permissions_handler(12775): No permissions found in manifest for: []22

Code

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"),
        ),
      ),
    );
  }
}

I'm using permission_handler (https://pub.dev/packages/permission_handler) package.

I tried this solutions but it is not working.

Faizan Kamal
  • 1,732
  • 3
  • 27
  • 56

4 Answers4

3

Check your targetSdkVersion in build.gradle file.

If you are using Android 11 (targetSdkVersion = 30), you will need to write this permission in manifest differently. You can try the solution discussed in this post

jiachenxu
  • 53
  • 5
1

For people how experienced the issue also,

Add this permission in your manifest file under <Manifest tag

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

I have the same error, I solved it by creating a new flutter project and copy my code to the new

0
Map<Permission, PermissionStatus> statuses = await [
  Permission.storage,
  Permission.manageExternalStorage,
].request();

var storage = statuses[Permission.storage];
var manageExternalStorage = statuses[Permission.manageExternalStorage];
if (storage.isGranted || manageExternalStorage.isGranted) {
  // do something
}
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
  • You should add explanation. – Super Kai - Kazuya Ito Jun 17 '23 at 06:02
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 21 '23 at 01:04