Search code examples
androidxamarinxamarin.androidandroid-cameraandroid-manifest

Android : android.permission.CAMERA, but was not found in your AndroidManifest.xml file


My android application sometimes crashes randomly when the app is launched and when I check my analytics report, the exception I get is :

{third party tool} requires android.permission.CAMERA, but was not found in your AndroidManifest.xml file.

PermissionsHandler.CheckPermissions (Android.Content.Context context, System.String permission, System.Boolean throwOnError)

PermissionsHandler.CheckCameraPermissions (Android.Content.Context context, System.Boolean throwOnError)CameraController.SetupCamera () CameraAnalyzer.SetupCamera ()

The tool I used for barcode doesn't even use camera service until user navigates to certain page. I just feel that probably at run time it is looking for camera permissions and sometimes the app manifest is not ready or doesn't load so the app assumes camera permissions are not included in the appmanifest even though they are.

My question is

  1. Does AndoridManifest right at the start of the application or Do I have to do some changes to the application to make sure it waits until manifest it ready with all permission settings?
  2. Does anyone faced similar error or can suggest any options to resolve ?

UPDATE: ZXing is a third party tool that needs camera service. But this thirty party API is being called in certain pages once the app launches and on these pages it requests for camera permission but app crashes at launch time with this exception: Exception:

PermissionsHandler.CheckPermissions (Android.Content.Context context, System.String permission, System.Boolean throwOnError)
System.UnauthorizedAccessException: ZXing.Net.Mobile requires: android.permission.CAMERA, but was not found in your AndroidManifest.xml file.

PermissionsHandler.CheckPermissions (Android.Content.Context context, System.String permission, System.Boolean throwOnError)

PermissionsHandler.CheckCameraPermissions (Android.Content.Context context, System.Boolean throwOnError)

CameraController.SetupCamera ()

CameraAnalyzer.SetupCamera ()

ZXingSurfaceView+<SurfaceCreated>d__3.MoveNext ()

ExceptionDispatchInfo.Throw ()

AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)

SyncContext+<>c__DisplayClass2_0.<Post>b__0 ()

Thread+RunnableImplementor.Run ()

IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this

Solution

  • I found the solution here : Application crashes when asking for permissions

    This code in your OnRequestPermissionsResult:

      Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
      for (int i = 0; i < permissions.Length; i++)
      {
        if (permissions[i].Equals("android.permission.CAMERA") && grantResults[i] == Permission.Granted)
          global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
      }
      base.OnRequestPermissionsResult(requestCode, permissions, grantResults);