fix: allow camera usage when microphone permission is denied on Windows#3140
fix: allow camera usage when microphone permission is denied on Windows#3140AopBK wants to merge 1 commit intoCommunityToolkit:mainfrom
Conversation
| } | ||
|
|
||
| var cameraPermissionStatus = await Permissions.CheckStatusAsync<Permissions.Camera>(); | ||
| if (cameraPermissionStatus == PermissionStatus.Granted) |
There was a problem hiding this comment.
We removed all permission checks from the library. It is now up to developers to request permission they need and when they need, with the way to use their own UI for user permissions.
There was a problem hiding this comment.
Thank you for the clarification.
In my PR, the CameraViewExtensions.Windows.cs only checks the permission status, but does not request or manage permissions. The actual permission requests are handled in the CameraViewPage, as expected.
@VladislavAntonyuk ,could you please advise on how to best implement this in line with the library’s current design?
For example, should I pass a parameter from the manager, or is there another approach you recommend?
|
@AopBK please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
There was a problem hiding this comment.
Pull request overview
Adjusts Windows MediaCapture initialization for CameraView so camera usage can continue when microphone permission is denied, preventing UnauthorizedAccessException crashes (Issue #3139).
Changes:
- Build
MediaCaptureInitializationSettingsdynamically based on microphone permission/capability state. - Add a camera permission status check and throw a
CameraExceptionwhen not granted.
| @@ -1,5 +1,6 @@ | |||
| using CommunityToolkit.Maui.Core; | |||
There was a problem hiding this comment.
Permissions and PermissionStatus are used in this file, but there is no using Microsoft.Maui.ApplicationModel; (or fully-qualified references). Unless there’s a project-wide global using (none found in this project), this will not compile on Windows. Add the appropriate using or fully qualify the types.
| using CommunityToolkit.Maui.Core; | |
| using CommunityToolkit.Maui.Core; | |
| using Microsoft.Maui.ApplicationModel; |
| } | ||
| else | ||
| { | ||
| throw new CameraException("Camera permission is not granted."); |
There was a problem hiding this comment.
The new CameraException message is less actionable than other platform messages (e.g., iOS includes guidance to enable permissions in settings). Consider expanding this message to tell Windows users where to enable camera access (e.g., Windows Privacy settings / app permissions), or align it with the existing wording used elsewhere in the camera implementation.
| throw new CameraException("Camera permission is not granted."); | |
| throw new CameraException("Camera permission is not granted. To enable camera access, open Windows Settings > Privacy & security > Camera and allow camera access for this app."); |
TheCodeTraveler
left a comment
There was a problem hiding this comment.
Is there a better way to fix the linked issue without using Permissions.CheckStatusAsync?
CommunityToolkit.Maui.Camera (and all MAUI Toolkit libraries) now defers all permissions requests to the developers consuming our library:
https://github.com/CommunityToolkit/Maui/releases/tag/6.0.0-camera
Description of Change
The settings for initialising MediaCapture now differ depending on whether microphone permissions have been granted. This prevents the app from crashing due to an UnauthorizedAccessException.
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information