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]: Photo permission, 'Selected Photos Access enabled' error on Android 34 #1243

Open
3 of 5 tasks
alexlozdev opened this issue Dec 6, 2023 · 8 comments
Open
3 of 5 tasks
Labels
P2 Important issues not at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working

Comments

@alexlozdev
Copy link

alexlozdev commented Dec 6, 2023

Please check the following before submitting a new issue.

Please select affected platform(s)

  • 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)

@fuxianwei
Copy link

+1

@alexlozdev alexlozdev changed the title [Bug]: Photo permission error on Android 34 [Bug]: Photo permission, 'Only Selected Image' error on Android 34 Dec 6, 2023
@alexlozdev alexlozdev changed the title [Bug]: Photo permission, 'Only Selected Image' error on Android 34 [Bug]: Photo permission, 'Selected Photos Access enabled' error on Android 34 Dec 6, 2023
@Howard2595

This comment has been minimized.

@TimHoogstrate TimHoogstrate self-assigned this Jan 2, 2024
@mvanbeusekom mvanbeusekom added platform: android Issue is related to the Android platform. type: bug Something isn't working P2 Important issues not at the top of the work list. labels Jan 15, 2024
@mvanbeusekom
Copy link
Member

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

@anietoambling

This comment has been minimized.

@pranavo72bex

This comment has been minimized.

@mvanbeusekom
Copy link
Member

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.

@pranavo72bex
Copy link

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
Copy link

pranavo72bex commented May 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important issues not at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants