Getting Permission to Camera on Cross-Platform Applications

hkiddhkidd ✭✭Member ✭✭

I am working on a Cross-Platform app using .NET 2.0 Standard. I am currently using the Permissions Plugin by @JamesMontemagno , but am looking for a way to gain access to the camera without having to navigate the user out of my application and to settings. Rather, I would like a dialog box to pop up with the options "deny" and "allow". Is there a cross-platform way to implement this or will I need to either navigate the user to app settings or implement a platform specific implementation that will use platform-specific permission requesting APIs?

Posts

  • JoeMankeJoeManke ✭✭✭✭✭ USMember ✭✭✭✭✭

    Are you calling OpenAppSettings() instead of RequestPermissionsAsync()?

  • hkiddhkidd ✭✭ Member ✭✭

    Here is a snippet of my code. I may have implemented it incorrectly? It doesn't pull up a dialog box when I request permissions. It returns Unknown for the cameraStatus and wouldn't return as Granted until I navigated settings using OpenAppSettings().

        public void CreateGestureRecognizer()
        {
            var gesture = new TapGestureRecognizer();
            Camera.GestureRecognizers.Add(gesture);
            gesture.Tapped += async (sender, e) =>
            {
                var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
                if (cameraStatus != PermissionStatus.Granted)
                {
                    CrossPermissions.Current.OpenAppSettings();
                }
            };
        }
    
  • JoeMankeJoeManke ✭✭✭✭✭ USMember ✭✭✭✭✭

    Use CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera) instead of OpenAppSettings(), that will give you the dialog you want.

  • hkiddhkidd ✭✭ Member ✭✭

    @JoeManke Clarification: I am developing using .NET 2.0 Standard, which is incompatible with the CurrentActivity plugin, which I believe is causing the problem with the Unknown result returning from the RequestPermissionStatusAsync().

  • hkiddhkidd ✭✭ Member ✭✭

    @JoeManke For example, even when my code is configured as below, it returns the cameraStatus as Unknown. I believe it is because CurrentActivity isn't implemented?

        public void CreateGestureRecognizer()
        {
            var gesture = new TapGestureRecognizer();
            Camera.GestureRecognizers.Add(gesture);
            gesture.Tapped += async (sender, e) =>
            {
                var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);
                cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
                if (cameraStatus != PermissionStatus.Granted)
                {
                    CrossPermissions.Current.OpenAppSettings();
                }
            };
        }
    
  • JoeMankeJoeManke ✭✭✭✭✭ USMember ✭✭✭✭✭

    What do you mean the CurrentActivity plugin isn't compatible with .NET Standard 2.0? You should only be installing it into your Android project.

    And yeah, nothing is going to work if you don't have CurrentActivity set up properly. That's why it's a dependency.

  • hkiddhkidd ✭✭ Member ✭✭

    @JoeManke OH wow thank you so much!! It's working now

Sign In or Register to comment.