question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnauthorizedAccessException when denying camera access

See original GitHub issue

Hello,

I’m using ZXingScannerView in my app. When I push the button which opens the page containing that control a popup appears asking for camera permissions (Camera permissions are set in the visual studio project file for the android app). When I accept the permissions everything runs fine, but when I deny it the app crashes with an UnauthorizedAccessException. On the page I simply added the control: <qr:ZXingScannerView x:Name="ScannerView" HorizontalOptions="FillAndExpand" OnScanResult="HandleScannerOnResultEvent" VerticalOptions="FillAndExpand" />

In the MainActivity.OnCreate I’m doing the following: Platform.Init(); MobileBarcodeScanner.Initialize(Application); and also in the MainActivity: public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults); } The last lines of the call stack are: 01-09 11:15:58.521 D/ZXing.Net.Mobile( 3973): System.NullReferenceException: Object reference not set to an instance of an object. 01-09 11:15:58.521 D/ZXing.Net.Mobile( 3973): at ZXing.Mobile.CameraAccess.CameraController.RefreshCamera () [0x0001e] in <819b29aa6d91462699e19a679be55a44>:0

I’m using ZXing v2.4.1. Android: several phones and tablets running Android version 6.0.1 and 8.0

Have I missed something in my implementation? Since the ScannerView control forces the popup and waits for the result as well I’m expecting that it will be handled there. Or do I have to do the check in advance before instantiating the control? But the projects main page says that ZXing handles the permission request for me.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Redthcommented, Mar 13, 2020

3.0.0 changes this behaviour. Now just a black screen appears instead of the exception.

1reaction
ioiooicommented, May 28, 2019

Same. Even using the samples provided in this repository causes the UnauthorizedAccessException to be thrown when denying access to the camera.

After further investigating this behaviour my colleagues and I found that this line in the PermissionHandler.cs is the cause. The message is kinda misleading in that it always says that permission was not found in the AndroidManifest.xml even though it is and the actual reason is simply the User denying access.

Changing:

if (!IsPermissionInManifest(context, permission) || !IsPermissionGranted(context, permission))

to

if (!IsPermissionInManifest(context, permission))

Fixes the issue for our use case. Mind you the application still crashes when the camera permission is not present in the manifest.xml.

But the behaviour after changing the if statement is the following: User opens the ScanView or Activity and gets asked for the camera permission. If the User denies than the screen will be black/white whatever. If the User navigates back and forth will be asked again until the User accepts or checks ‘dont ask again’ and denies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access being denied to webcam in a UWP app
Both x64 and x86 builds give me the same access denied error i.e.. Exception thrown: 'System.UnauthorizedAccessException' in System.Private.
Read more >
UnauthorizedAccessException is raised in CameraControl ...
UnauthorizedAccessException is raised in CameraControl when the "Allow apps to access your camera" option is disabled.
Read more >
System.UnauthorizedAccessException: Access to the path ...
I am using the FileStream class to read a file as shown below, in Xamarin Forms(Android):. FileStream stream = new FileStream(_file.
Read more >
System.UnauthorizedAccessException during camera sync
UnauthorizedAccessException : Access to the path "/media/Camera/Josh - GS7/Camera" is denied. I have no idea how it decided ...
Read more >
System.UnauthorizedAccessException: Access to the path ...
UnauthorizedAccessException : Access to the path is denied. I keep getting the above error when Radarr imports movies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found