Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] getassetpathlist() returns empty results #942

Closed
asdjfasdfkljdas opened this issue Jul 5, 2023 · 8 comments
Closed

[Bug report] getassetpathlist() returns empty results #942

asdjfasdfkljdas opened this issue Jul 5, 2023 · 8 comments

Comments

@asdjfasdfkljdas
Copy link

Version

2.5.2

Platforms

dart, Android

Device Model

Various android phones

flutter info

[√] Flutter (Channel stable, 3.7.0, on Microsoft Windows [Version 10.0.22621.819], locale en-GB)
    • Flutter version 3.7.0 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b06b8b2710 (5 months ago), 2023-01-23 16:55:55 -0800
    • Engine revision b24591ed32
    • Dart version 2.19.0
    • DevTools version 2.20.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\dan\AppData\Local\Android\sdk
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] VS Code (version 1.79.2)
    • VS Code at C:\Users\dan\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.68.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.819]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 114.0.5735.199
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 114.0.1823.67

[√] HTTP Host Availability
    • All required HTTP hosts are available

How to reproduce?

I've shipped the following code to various android devices (2 tablets, 4 mobile phones).

On 2 of the mobile phones, getAssetPathList() simply returned nothing, an empty list. Works perfect on the other devices.

final PermissionState _ps = await PhotoManager.requestPermissionExtend();
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList();

What I've tried/ruled out before concluding it must be a bug in the lib:

All phones definitely have asset folders (directories with images, e.g. 'Camera')

All phones granted the exact same permission in the exact same way

There are no filters being applied to this call (I removed any filters to attempt to isolate the cause)

No errors are being thrown (I'm logging the count out as soon as this call has successfully returned)

Ruled out any version discrepancies, this is the exact same APK//build

One of the android devices it works on is my up to date brand new mobile phone. The other it works on is a 4 year old android tablet with an out of date OS, so I'm fairly certain it's not an OS-specific issue (could be wrong)

Logs

No response

Example code (optional)

final PermissionState _ps = await PhotoManager.requestPermissionExtend();
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList();

Contact

dan@stacksoftware.co.uk

@ArjunBhilare
Copy link

@asdjfasdfkljdas did you find any solution?

@asdjfasdfkljdas
Copy link
Author

@asdjfasdfkljdas did you find any solution?

It was on version 2.5.2. I updated the package to latest (2.6.0) and now it works.

I'm still confused as to why 2.5.2 would be broken though.

@ArjunBhilare
Copy link

ArjunBhilare commented Jul 7, 2023

@asdjfasdfkljdas

Even I have updated to 2.6.0 but

final List paths = await PhotoManager.getAssetPathList() is returning an empty list everytime in my app on Android 13. However if I run the example app it works very well on Android 13. I have added the

<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" /> <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

to the manifest. Am I missing something?

@asdjfasdfkljdas
Copy link
Author

asdjfasdfkljdas commented Jul 7, 2023

Can you share your code? Remove any filters etc. - reduce your code to the absolute minimum required to prove the issue and I'll take a look.

The only other thing I changed is to request permissions a little differently, here's my full code:

  final permissionStatus = await Permission.storage.status;
    if (permissionStatus.isDenied) {
      var newPermissionStatus = await Permission.storage.request();

      if (newPermissionStatus.isDenied) {
        await openAppSettings();
      } else {
  // Granted
 }
    } else if (permissionStatus.isPermanentlyDenied) {
      await openAppSettings();
    } else {
      // Already granted
    }

      List<AssetPathEntity> albums = await PhotoManager.getAssetPathList();

I'm using the following package for this:

permission_handler: 10.4.1

I don't consider this the solution, since I don't think it worked with this changed, it worked as of the version update. But this is definitely worth a try as it's exactly the same set-up as mine, and mine works now.

If you have a version that works (the example app), and a version that doesn't (yours), the answer lies in whatever the difference is.

I'd take the approach of building up the example app until the problem's reproduced (or vice versa, reduce your own custom app until the problem goes away).

@ArjunBhilare
Copy link

ArjunBhilare commented Jul 7, 2023

I have copied the code from the example app, and made everything the same, still the getAssetPathList returns empty list. Any changes in the Android files that I am missing?

I am using this code in my app https://github.com/phuongtinhbien/album_image/tree/master/lib/src so instead of importing album_image, I manually added the code and in that I want to edit album_image_picker.dart. This works perfectly on Android 12 or below. Any suggestion what could be broken?

@ArjunBhilare
Copy link

ArjunBhilare commented Jul 7, 2023

Solved it!!, I had set the targetSdkVersion to 32, changed it to 33 and it started working

@CaiJingLong
Copy link
Member

So, the problem is that the target sdk version is not the 33 or higher?

@AlexV525
Copy link
Member

Duplicate of #852

@AlexV525 AlexV525 marked this as a duplicate of #852 Jul 17, 2023
@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants