Baseflow / flutter-permission-handler

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
https://baseflow.com
MIT License
2.04k stars 850 forks source link

[Bug]: Permission Handler in Android 13 permission denied #1143

Closed Joe2316 closed 1 year ago

Joe2316 commented 1 year ago

Please check the following before submitting a new issue.

Please select affected platform(s)

Steps to reproduce

Hello,

I'm currently using Permission_handler package version 10.4.3 in Flutter, and I ran into an issue with targetSdkVersion in Android.

When I set targetSdkVersion to 33, I get "Permission Denied" issues when trying to save images from my app to phone gallery. Despite trying different solutions to address this issue, I was only able to resolve it by reverting targetSdkVersion to version 32.

Expected results

I am seeking guidance on how to resolve this issue without compromising the requirements to target Android 13 (API level 33) or higher. Any ideas or suggestions on how to make the Permission_handler package compatible with the latest Android SDK would be greatly appreciated.

Actual results

Code sample

Code sample ```dart [Paste your code here] ```

Screenshots or video

Screenshots or video demonstration ![android 33](https://github.com/Baseflow/flutter-permission-handler/assets/137117951/a86bfda1-7be6-4e4a-b09f-714df0bcfe4c) ![android 32](https://github.com/Baseflow/flutter-permission-handler/assets/137117951/71774d5f-6591-4db1-baaa-4389f088dba2) ![android 32 save image](https://github.com/Baseflow/flutter-permission-handler/assets/137117951/670973a0-2189-4a57-8302-51b2adea0125) ![warning](https://github.com/Baseflow/flutter-permission-handler/assets/137117951/bced06f8-697c-4738-94fb-187008c57ccd) >

Version

10.4.3

Flutter Doctor output

Doctor output ```console [Paste your output here] ``` PS C:\Users\MS\StudioProjects\image_ai> flutter doctor ┌─────────────────────────────────────────────────────────┐ │ A new version of Flutter is available! │ │ │ │ To update to the latest version, run "flutter upgrade". │ └─────────────────────────────────────────────────────────┘ Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [Version 10.0.19044.1288], locale en-US) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0) [√] Android Studio (version 2021.1) [√] Android Studio (version 2021.3) [√] VS Code (version 1.81.1) [√] Connected device (4 available) [√] Network resources
nguyenvanan18031993 commented 1 year ago

I have the same problem with @Joe2316 . Did you find out the solution?

JeroenWeener commented 1 year ago

Hi @Joe2316, @nguyenvanan18031993!

Could it be that you are requesting the wrong permission? Since Android 13, the permissions for accessing files have had an update. You can read about it in our FAQ: https://pub.dev/packages/permission_handler#faq and on the Android documentation located here: https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions.

mohamedsalah83 commented 1 year ago

I found the solution after adding permission to androidmanifest.xml @JeroenWeener @nguyenvanan18031993 @Joe2316

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

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>

then permission_handler (request) "look to photo"

await Permission.photos.request();

Untitled

Untitled2

Joe2316 commented 1 year ago

Worked for me .. Thanks :)) i was request storage but didn't work for me, final status = await Permission.storage.request(); but after await Permission.photos.request(); works good