Permission is always granted for Gallery , photos

Manickam, Suraj 320 Reputation points
2024-03-13T08:47:29.3366667+00:00

I implemented media picker where user can select camera or gallery, on click of camera , it prompts the user to provide access to capture images but on click of gallery by default it opens the gallery without any permission request .

i tried by checking

PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.Photos>();

by default it comes as granted. Why is it not prompting the user to provide access to gallery?

Android versions tested : 9-13

MAUI version : 8

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-03-14T07:30:05.2633333+00:00

    Hello,

    ==============================Update=================

    Android versions we have two popups coming up when media picker camera is selected Any explanation on why we get two popups?

    Firstly, let see CapturePhotoAsync's source code. It invoke the CaptureAsync method, You will see await Permissions.EnsureGrantedAsync<Permissions.Camera>(); and await Permissions.EnsureGrantedAsync<Permissions.StorageWrite>(); in the CaptureAsync method. It requests two permissions.

    You will get two popups about permission, one is camera and other is storage permssion.

    Permissions.Photos isn't supported or isn't required for android platform. So you will always get the Granted.

    Please see Available permissions

    The following table uses ✔️ to indicate that the permission is supported and ❌ to indicate the permission isn't supported or isn't required:

    Then, we can open the source code about media picker's PickPhotoAsync, it will invoke the PickAsync . And use var intent = new Intent(Intent.ActionGetContent); to picker images. This way is not your application to access the external storage. The Android system will then launch the best application to select that kind of data for you. So you need not need request permissions.

    Please see Intent#ACTION_GET_CONTENT from naive android document.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.