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

[How to use] Android API 34 ACCESS_MEDIA_LOCATION is denied if user selected limited access to photos and videos #1089

Open StigUK opened 3 months ago

StigUK commented 3 months ago

Platforms

Android

Description

I am requesting access to media files on Android 14 (api 34) using PhotoManager (version 3.0.0-dev.5). Provided that the user chooses not full, but limited access to the gallery of permissions, ACCESS_MEDIA_LOCATION is always returned as denied. This means I can't get coordinates from the metadata of a photo or video.

If the user gives full access, then the ACCESS_MEDIA_LOCATION status is returned as granted.

I don’t know for sure whether this is a library bug, or whether it’s a feature of API 34, which is why I didn’t file this as a bug report.

My code

import 'package:photo_manager/photo_manager.dart'; import 'package:permission_handler/permission_handler.dart';

Future test() async { final PermissionState permissionState = await PhotoManager.requestPermissionExtend(); final PermissionStatus accessMediaLocationStatus = await Permission.accessMediaLocation.status; ///If permissionState is limited => accessMediaLocationStatus is denied ///If permissionState is authorized => accessMediaLocationStatus is granted }

Try do it

No response

ashilkn commented 2 months ago

@StigUK I was facing ACCESS_MEDIA_LOCATION denied/not-requested issue on photo_manager v2.8.1. It's not exactly your issue, but this helped me resolve mine.

 final permissionState = await PhotoManager.requestPermissionExtend(
        requestOption: const PermissionRequestOption(
          androidPermission: AndroidPermission(
            type: RequestType.common,
            mediaLocation: true,
          ),
        ),
      );

mediaLocation is set to false by default, changing it fixed my issue. See if this works for you as well?

mozammal-Hossain-dev commented 1 month ago

@StigUK , you can try @ashilkn's solution and also give the below permission for the Android:

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

These procedures solved the issue for Android API 34.