Search code examples
androidflutterdartandroid-permissionstargetsdkversion

How to fix the error Cannot open file, path = '/storage/emulated/0/DCIM/Camera/20200818_123041.jpg' (OS Error: Permission denied, errno = 13)


I'm trying to allow a user to pick an image from their photo gallery on their device.

My previous code worked fine, but now that I have to update the targetSdkVersion from 28 to 29, its not working any more.

I've tried adding

 <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"/>

But still not working. Also tried using the permission_handler flutter package.

Any help is greatly appreciated!

Thanks, Jason.


Solution

  • I managed to solve my problem in the end. I needed to set android:requestLegacyExternalStorage="true" in android manifest, and change the compileSdkVersion to 29 aswell (it was still on 28, even though I'd changed the targetSdkVersionto 29) - you must need to change both in the app level build.gradle.

    Hope this helps someone, so glad I fixed my issue!