flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

[Bug]: Photo permission, 'Selected Photos Access enabled' error on Android 34

Open scrtkr opened this issue 2 years ago • 18 comments

Please check the following before submitting a new issue.

Please select affected platform(s)

  • [X] Android
  • [ ] iOS
  • [ ] Windows

Steps to reproduce

AndroidManifest.xml

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

<!-- Devices running Android 13 (API level 33) or higher -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- To handle the reselection within the app on Android 14 (API level 34) -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

When selecting 'Selected Photos Access enabled', it always return PermissionStatus.permanentelyDenied 2

Expected results

PermissionStatus.granted

Actual results

PermissionStatus.permanentelyDenied

Code sample

Code sample
late PermissionStatus newPermReq;

    final deviceInfo = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      final androidInfo = await deviceInfo.androidInfo;
      final androidSdkInt = androidInfo.version.sdkInt ?? 0;
      if (androidSdkInt < 33) {
        newPermReq = await Permission.storage.request();
      } else {
        newPermReq = await Permission.photos.request();
      }

    } else if (Platform.isIOS) {
      newPermReq = await Permission.photos.request();
    }

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

11.1.0

Flutter Doctor output

Doctor output
![01](https://github.com/Baseflow/flutter-permission-handler/assets/61686168/7135a115-6342-4710-bbc1-2199b7a7554a)


scrtkr avatar Dec 06 '23 09:12 scrtkr

+1

fuxianwei avatar Dec 06 '23 10:12 fuxianwei

same

Howard2595 avatar Jan 02 '24 08:01 Howard2595

Thank you for pointing this out, we have labelled the issue as a bug and added it to our backlog.

mvanbeusekom avatar Jan 15 '24 10:01 mvanbeusekom

same, I need this android 14 feature working well please don't abandon it

anietoambling avatar Apr 09 '24 09:04 anietoambling

same

pranavo72bex avatar May 09 '24 09:05 pranavo72bex

Instead of saying "I have the same", which really doesn't help resolving the issue, try to provide more information about the bug.

An example app reproducing the behavior for example would be of great help.

mvanbeusekom avatar May 09 '24 09:05 mvanbeusekom

Instead of saying "I have the same", which really doesn't help resolving the issue, try to provide more information about the bug.

An example app reproducing the behavior for example would be of great help.

Upon testing the application on my Samsung M15 device running Android 14, I encountered a "permission denied" error. However, the same application functions correctly on BrowserStack's simulated Samsung phone with Android 14 😕

pranavo72bex avatar May 09 '24 10:05 pranavo72bex

Instead of saying "I have the same", which really doesn't help resolving the issue, try to provide more information about the bug.

An example app reproducing the behavior for example would be of great help.

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: PermissionExample(),
    );
  }
}

class PermissionExample extends StatefulWidget {
  const PermissionExample({super.key});

  @override
  _PermissionExampleState createState() => _PermissionExampleState();
}

class _PermissionExampleState extends State<PermissionExample> {
  PermissionStatus? _permissionStatus;

  @override
  void initState() {
    super.initState();
    _checkPermissionStatus();
  }

 Future<void> _checkPermissionStatus() async {
    final androidInfo = await DeviceInfoPlugin().androidInfo;
    PermissionStatus status;
    if (androidInfo.version.sdkInt <= 32) {
      status = await Permission.storage.request();
    } else {
      status = await Permission.photos.request();
    }
    setState(() {
      _permissionStatus = status;
    });
  }

  Future<void> _requestPermission() async {
    PermissionStatus
        status; // Declared the status variable outside the try-catch block
    try {
      status = await Permission.photos.request();
    } catch (e) {
      status =
          PermissionStatus.denied; // Handled the exception in case of an error
    }
    setState(() {
      _permissionStatus = status;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Photo Permission Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Photo Permission Status: ${_permissionStatus ?? "Unknown"}',
              style: const TextStyle(fontSize: 18),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _requestPermission,
              child: const Text('Request Permission'),
            ),
          ],
        ),
      ),
    );
  }
}
<!-- Permission to read files from external storage (outside application container). 
         As of Android 12 this permission no longer has any effect. Instead use the 
         READ_MEDIA_IMAGES, READ_MEDIA_VIDEO or READM_MEDIA_AUDIO permissions. -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <!-- Permissions to read media files. -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
 permission_handler: ^11.3.1
  device_info_plus: ^10.1.0

Please try with this code. It is showing always permission denied. There is no implementation of this feature https://developer.android.com/about/versions/14/changes/partial-photo-video-access

I manage to fix the behavior by this package https://pub.dev/packages/photo_manager

Screenshot 2024-05-10 at 11 16 20 Screenshot 2024-05-10 at 11 16 47

pranavo72bex avatar May 10 '24 05:05 pranavo72bex

@AnujLM it is still not working. Could you please provide an example of how it works.

QL-Uday avatar Aug 09 '24 06:08 QL-Uday

This issue should be resolved with the latest update of the permission_handler_android package (which the permission_handler depends on).

@pranavo72bex, @QL-Uday, can you verify if you application is using version 12.0.8 of the permission_handler_android package? To verify the version used by the application open the pubspec.lock file and find the entry for permission_handler_android package.

If the application is not on version 12.0.8, run flutter pub upgrade permission_handler_android to update to the latest version and test again.

mvanbeusekom avatar Aug 09 '24 06:08 mvanbeusekom

In my application, I am using the following versions: permission_handler: 11.3.1 permission_handler_android: 12.0.8 permission_handler_platform_interface: 4.2.2

These are the latest available. But still it is not working, giving "PermissionStatus.denied", upon clicking limited access. I am request the Permission.photos .

QL-Uday avatar Aug 09 '24 10:08 QL-Uday

Hey, I had the same issue and I'm using the same versions as @QL-Uday. After I completely uninstalled and reinstalled my app - as well as running flutter clean && flutter pub get -> it worked. Thanks @mvanbeusekom. Maybe @QL-Uday can you try to also uninstall and reinstall to see if it helps?

novas1r1 avatar Aug 12 '24 09:08 novas1r1

@novas1r1 , I was already doing that too. But for a confirmation, I again performed these step, still unsuccessful.

QL-Uday avatar Aug 12 '24 09:08 QL-Uday

I am currently working with compileSdk 34 and targetSdk 34. In my AndroidManifest.xml file, I have included the following permissions:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

@novas1r1 , @mvanbeusekom , Could you please advise if there are any additional permissions or configurations required to ensure that "Limited access" functionality works as expected?

Thank you for your assistance.

QL-Uday avatar Aug 13 '24 07:08 QL-Uday

For the issue I encountered, by removing the "READ_MEDIA_VISUAL_USER_SELECTED" permission from my app's AndroidManifest.xml file resolved the problem. It appears that this permission was causing conflicts with another permission added by the permission_handler library in the same manifest file.

Thank you for your assistance in this matter.

QL-Uday avatar Aug 14 '24 06:08 QL-Uday

There is a workaround. Permission.photos.request() is returning PermissionStatus.denied, but Permission.photos.isLimited returns true.

So you can call Permission.photos.request() and do not check answer of this call but than check if user granted permissions using this code

await Permission.photos.isGranted || await Permission.photos.isLimited

VladShturma avatar Aug 14 '24 13:08 VladShturma