Flutter image_picker 报错权限错误 (photo_access_denied, The user did not allow photo access., null)

按照pub上面下载image_picker后,在安卓中运行报错:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception:
PlatformException(photo_access_denied, The user did not allow photo
access., null)

这上面说“用户不允许访问照片”,但是官网明明写着"No configuration required - the plugin should work out of the box.“ - 开箱即用。
我在GITHUB上做了参考。

其实

应该在Android项目的AndroidManifest.xml(所有的都加上)中加入:

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

这样安卓就有权限访问手机的相册了,如下图:
Flutter image_picker 报错权限错误 (photo_access_denied, The user did not allow photo access., null)_第1张图片

添加完之后
  1. 在 Android 里面
    Build --> Clean Project
    Build --> Rebuild Project
  2. 在 Flutter 里面
    flutter clean

你可能感兴趣的