Home > Mobile >  requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()

Time:01-02

exception code is here

when using Image-Picker package and run ,this exception is showing . image is not shows in the container after taking the image..

CodePudding user response:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.yyy">
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
...
</manifest>

You also need Runtime Request Permission, by using permission_handler 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 pop up 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.

CodePudding user response:

When using the "image picker" package in Flutter, it appears that you are having issues with the Android permissions necessary to access the external storage.

To resolve this issue, add the "WRITE EXTERNAL STORAGE" permission to your Android app's manifest file. This is accomplished by include the following line in your "AndroidManifest.xml" file:

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

If your app is targeting Android 6.0 (API level 23) or higher, you will additionally need to seek this permission from the user during runtime. You may accomplish this by use the "permission handler" package or the built-in Android "requestPermissions()" function. Here's an example of how you may use the "permission handler" package to request the "WRITE EXTERNAL STORAGE" permission:

  • Related