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] Android 13 - PhotoManager.getAssetPathList(hasAll: true) returns empty list #852

Closed
davidbrenner opened this issue Oct 27, 2022 · 10 comments

Comments

@davidbrenner
Copy link

Describe the bug
On android version 13, PhotoManager.getAssetPathList(hasAll: true) always returns an empty list

To Reproduce

code sample:

    var result = await PhotoManager.requestPermissionExtend();
    if (result.isAuth) {
      // success
      photoPermissionGranted = true;
      //load the album list
      List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(hasAll: true);
      print(albums);
    }

Expected behavior
Should return a list of media, as it does on iOS and on android version < 13

Flutter version

Smartphone (please complete the following information):

  • Device: emulated pixel c tablet, also seen on pixel 6
  • OS: Android 13

Log
n/a

@davidbrenner
Copy link
Author

FWIW - I also cloned this repository and tried running the example demo on these devices and I see the same behavior. Any pointers on how to resolve or work around this would be greatly appreciated.

@AlexV525
Copy link
Member

image

@majd-fouuqhaa
Copy link

@davidbrenner, @AlexV525 I faced the same issue with android 13, I did everything explained in the documentation with no luck.

Then I added READ_EXTERNAL_STORAGE to the list of permissions inside AndroidManifest.xml like this
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE>" />

and it worked, hope this may help you

@AlexV525
Copy link
Member

Pixel C Tablet emulator.

image

@AlexV525
Copy link
Member

Be aware, emulators won't detect images unless you manually browse them first from the file manager, then a reboot is required in addition.

Closing as it seems invalid and not related.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2022
@davidbrenner
Copy link
Author

@AlexV525 and @majd-fouuqhaa - thanks for investigating and for the pointers. I don't know exactly which one unlocked this for me, but I can confirm I got it to work between the 2 of your suggestions (rebooting the emulator and adding READ_EXTERNAL_STORAGE.

Confirmed that this was invalid and good to close. Hopefully if someone else runs into this, the suggestions in this thread work for them as well.

@SuhwanCha
Copy link

@davidbrenner
In my case, minSdkVersion, compileVersion, targetSdkVersion is matter.
I've updated minSdkVersion to 21, compileVersion to 33, targetSdkVersion to 33. Then it works.

@erisanolasheni
Copy link

erisanolasheni commented Jan 6, 2023

For Android 13, I added

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

And used permission_handler
To request media library and photos permission

final permitted = await Permission.mediaLibrary.request().isGranted &&
        await Permission.photos.request().isGranted;

Updated:
I was able to get it working without Permission.photos.request().isGranted:

final permitted = await Permission.mediaLibrary.request().isGranted;

And it worked.
Note: I also upgraded targetSdkVersion 33 in app build.gradle.

@HaoCherHong
Copy link

@erisanolasheni

I was able to get it working without Permission.photos.request().isGranted:

I found that in production, if you request without Permission.photos, it returns still empty array.
(Only in Android production)

@deevsaini
Copy link

Nothing works in my case also , same issue androdi 13 pxel 4 , tried emulator and real device aslo

 getData() async {
    PermissionStatus status;
    final deviceInfo = await DeviceInfoPlugin().androidInfo;

    if (deviceInfo.version.sdkInt > 32) {
      status = await Permission.photos.status;
    } else {
      status = await Permission.storage.status;
    }
    print("status $status");
    if (status.isGranted == false) {
      if (!mounted) {
        return;
      }
      return showCupertinoDialog(
          context: context,
          barrierDismissible: false,
          builder: (_) => CustomDialog(
                showCross: false,
                title: Text(
                  "Permission Required",
                  style: CustomStyles.headingTextStyle,
                ),
                content: const Text(
                  '''This Permission allows Digrowfa to let you choose which photos/videos to share with your friends/connections.''',
                  textAlign: TextAlign.center,
                ),
                actions: [
                  Center(
                    child: RoundedButton(
                      width: Dimensions.screenWidth * 0.7,
                      color: Constants.primaryColor,
                      child: const Text("Ok"),
                      onPressed: () {
                        if (status.isPermanentlyDenied) {
                          Navigator.pop(context);
                          openAppSettings();
                        } else {
                          _fetchNewMedia();
                        }
                        Navigator.pop(_);
                      },
                    ),
                  ),
                  CupertinoDialogAction(
                    child: const Text("cancel"),
                    onPressed: () {
                      Navigator.pop(_);
                      Navigator.pop(context);
                    },
                  ),
                ],
              ));
    } else {
      _fetchNewMedia();
    }

    return null;
  }

  Future<void> _fetchNewMedia() async {
    lastPage = currentPage;
    final deviceInfo = await DeviceInfoPlugin().androidInfo;
    var result;
    if (deviceInfo.version.sdkInt > 32) {
      result = await Permission.photos.request();
    } else {
      result = await Permission.storage.request();
    }
    print(result);
    if (result == PermissionStatus.granted) {
      List<AssetPathEntity> albums = await PhotoManager.getAssetPathList();
      print(albums);
      if (dropList.isEmpty) {
        for (var i in albums) {
          if (await i.assetCountAsync != 0) {
            dropList.add(DropdownMenuItem(
              value: albums.indexOf(i),
              child: Text(i.name,
                  style: CustomStyles.mediumBodyTextStyle
                      .copyWith(color: Colors.white)),
            ));
          }
        }
      }
      List<AssetEntity> media = await albums[listIndex]
          .getAssetListPaged(page: currentPage, size: 12);

      List<Widget> temp = [];
      if (albums.isNotEmpty) {
        for (var asset in media) {
          mediaFile = await asset.file;
          if (widget.type == UploadType.shout) {
            if (asset.type == AssetType.video) {
              paths.add({"file": mediaFile, "type": asset.type});
              addToTemp(temp, asset);
            }
          } else {
            paths.add({"file": mediaFile, "type": asset.type});
            addToTemp(temp, asset);
          }
        }
      } else {}
      if (!mounted) return;
      setState(() {
        _mediaList.addAll(temp);
        currentPage++;
      });
    } else {
      if (!mounted) {
        return;
      }
      showCupertinoDialog(
          context: context,
          builder: (_) => CustomDialog(
                title: const Text("Permission Issue"),
                content: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const Text(
                        "It seems like Digrowfa doesn't have access to your File and Images, Please Go to the App Settings and Provide them Manually."),
                    addVerticalSpace(40),
                    RoundedButton(
                      color: Constants.primaryColor,
                      onPressed: () {
                        PhotoManager.openSetting();
                      },
                      child: const Text("Go to Settings"),
                    )
                  ],
                ),
              ));
    }
  }

PhotoManager.getAssetPathList() always returns [] for android 13

<uses-permission
     android:name="android.permission.READ_EXTERNAL_STORAGE"/>
 <uses-permission
     android:name="android.permission.WRITE_EXTERNAL_STORAGE"
     android:maxSdkVersion="28"/>
 <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.READ_CONTACTS"/>

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

7 participants