fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
647 stars 297 forks source link

[Bug report] requestPermissionExtend() always return PermissionState.denied on Android 13 #1090

Closed xiao-gy closed 3 months ago

xiao-gy commented 3 months ago

Version

3.0.0-dev.5

Platforms

Android

Device Model

Android Virtual Device(Android 13)

flutter info

```sh [√] Flutter (Channel stable, 3.16.8, on Microsoft Windows [版本 10.0.22631.3155], locale zh-CN) • Flutter version 3.16.8 on channel stable at D:\dev\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 67457e669f (5 weeks ago), 2024-01-16 16:22:29 -0800 • Engine revision 6e2ea58a5c • Dart version 3.2.5 • DevTools version 2.28.5 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at D:\dev\Android\sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = D:\dev\Android\sdk • Java binary at: D:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2023.1) • Android Studio at D:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) [√] VS Code (version 1.86.2) • VS Code at C:\Users\xiao-gy\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.82.0 [√] Connected device (4 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 10.0.22631.3155] • Chrome (web) • chrome • web-javascript • Google Chrome 122.0.6261.69 • Edge (web) • edge • web-javascript • Microsoft Edge 121.0.2277.128 [√] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```

How to reproduce?

When I run final PermissionState ps = await PhotoManager.requestPermissionExtend(); on Android 13, the value of ps is always PermissionState.denied , which causes an error when I use the camera module of wechat_camera_picker. However, the same code works fine on Android 14, so I believe it's not a lack of necessary permissions, but rather an error in the return of PhotoManager.requestPermissionExtend(). I have tried assigning ps a value of PermissionState.limited, and the code works fine on Android 13, which further indicates that requestPermissionExtend() is returning incorrect data.

I have tested this on Android 11, 13, and 14, and this issue only occurs on Android 13. I hope this can be fixed.

Logs

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Permission is not fully granted to save the captured file.
                                                                                                    #0      CameraPickerViewerState.createAssetEntityAndPop (package:wechat_camera_picker/src/states/camera_picker_viewer_state.dart:184:20)
                                                                                                    <asynchronous suspension>

Example code (optional)

final PermissionState ps = await PhotoManager.requestPermissionExtend();
AlexV525 commented 3 months ago

The example works on all API levels, no?

xiao-gy commented 3 months ago

The example works on all API levels, no?

I don't konw.But it doesn't work properly on Android 13 (at least that's when I tested it).

xiao-gy commented 3 months ago

I think I might need to test this function individually on Android 13.I'll try tomorrow.

xiao-gy commented 3 months ago

I think I might need to test this function individually on Android 13.I'll try tomorrow.

I try to write a simple code to verify this issue.The code is as follow:

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    abc();
    bcd();
    return Scaffold();
  }

  void abc() async{
    await Permission.photos.status;}
  void bcd() async{
    final PermissionState ps = await PhotoManager.requestPermissionExtend();
  }
}

And I write these in AndroidManifest.xml:

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

I run this code on Android 13 and Android 14 respectively and I got different result of ps. On Android 13 ,I got ps = PermissionState.denied. But on Android 14,I got ps = PermissionState.limited.

AlexV525 commented 3 months ago

Did you use the example to reproduce? Or it's your own project?

xiao-gy commented 3 months ago

Did you use the example to reproduce? Or it's your own project?

I just created a new project to verify the functionality of final PermissionState ps = await PhotoManager.requestPermissionExtend();.

AlexV525 commented 3 months ago

The example works on all API levels, no?

Please verify.

xiao-gy commented 3 months ago

The example works on all API levels, no?

Please verify.

Sry,I'm rookie in Android development, so I am not sure what you are referring to. QAQ

This is my config in build.gradle.

android {
    namespace "com.example.untitled"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileSdkVersion 34
    defaultConfig {
        ...
        flutter.minSdkVersion
        minSdkVersion 21
        targetSdkVersion 33
    }
}
AlexV525 commented 3 months ago

Run the example on Android 13 devices and see if the issue persist.

xiao-gy commented 3 months ago

Run the example on Android 13 devices and see if the issue persist.

I'm going to bed now. I'll try it out when I wake up.

Thank you for your help!

xiao-gy commented 3 months ago

I have resolved the above issue. It may have been caused by incomplete permissions declared in my AndroidManifest.xml. After referring to the example, I was able to resolve this problem successfully.

Thanks!