Getting permission to the external storage (file_provider plugin)

前端 未结 5 2147
星月不相逢
星月不相逢 2020-12-03 16:08

I\'m having some problems getting permissions to the external storage on android devices with flutter.

When I try to create a directory in my external storage I get

5条回答
  •  执念已碎
    2020-12-03 16:49

    Beside needing to add WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE to your android/app/src/main/AndroidManifest.xml

    
        
        
    ...
    
    

    You also need Runtime Request Permission, by using simple_permissions package:

    import 'package:simple_permissions/simple_permissions.dart';
    
    PermissionStatus permissionResult = await SimplePermissions.requestPermission(Permission. WriteExternalStorage);
    if (permissionResult == PermissionStatus.authorized){
      // code of read or write file in external storage (SD card)
    }
    

    Note:

    1. when running SimplePermissions.requestPermission for the First Time, app will popup a window, you MUST click ALLOW:

    to give permission.

    1. If you already clicked DENY, then uninstall debug app and re-debug it to install and fix this -> trigger the popup window and give you chance to click ALLOW.

提交回复
热议问题