Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storage Permission in Flutter

I am trying to get storage permission in the initstate() function of the class.I used two packages - Simple_Permissions and Permission package. But both give the same error to me.

FYI - I have put the permission in manifest already.

"E/SimplePermission( 6405): set to never ask againandroid.permission.WRITE_EXTERNAL_STORAGE I/SimplePermission( 6405): Requesting permission status : 4 I/flutter ( 6405): permission request result is PermissionStatus.deniedNeverAsk"

What I understood from this is that this error should come if the permission was set to "never ask again" by the user . But it is the first time I am requesting storage permission in my app .

What I have tried:

  1. Uninstalling and reinstalling the app.
  2. Using 2 different permission packages
  3. Running app on different Android Versions, different emulators.

Also:
I request 2 permissions in my app, one for location and other for writing storage.

When I go to the settings --> installed apps --> permissions --> I CAN see the permission for location and I can turn it on/off. But I CANNOT see permission for storage.

like image 701
Taha Ali Avatar asked Jan 23 '19 07:01

Taha Ali


People also ask

What are permissions in flutter?

Permissions are the way to interact application to mobile phone user to access a specific type of data. For example If want to access User Location in our android application then we must have to add the Access Location Permission in our flutter android project’s AndroidManifest.xml file.

Can flutter access the storage of the device we run on?

Flutter is an awesome toolkit. It allows us for fast UI iteration. But what if we are not able to access the storage of the device we’re running on? In this guide, we’ll go through how we can get the storage permission in a Flutter Application. For this guide, I assume you’re using an Android Device.

How to access storage using permission_handler?

Another way to access storage using permission_handler package status.isUndetermined is used to determine whether we had asked for permission yet or not. var status = await Permission.storage.status; if (status.isUndetermined) { // You can request multiple permissions at once.

Who is the developer of permission handler plugin for flutter?

This Permission handler plugin for Flutter is developed by Baseflow. You can contact us at [email protected]


2 Answers

Have you added the below code to android manifest file?

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
like image 80
Keerti Purswani Avatar answered Sep 21 '22 23:09

Keerti Purswani


Another way to access storage using permission_handler package

dependencies:
  permission_handler: ^5.0.1

Code Snippet

status.isUndetermined is used to determine whether we had asked for permission yet or not.

          var status = await Permission.storage.status;
           if (status.isUndetermined) {
                // You can request multiple permissions at once.
                Map<Permission, PermissionStatus> statuses = await [
                  Permission.storage,
                  Permission.camera,
                ].request();
                print(statuses[Permission.storage]); // it should print PermissionStatus.granted
              }

Note: Don't forget to add permission in AndroidMenifest for android & info.plist for iOS.

like image 32
Jitesh Mohite Avatar answered Sep 24 '22 23:09

Jitesh Mohite