Forum Xamarin.Android

My camera not reload after permission granted but after refresh apps the camera reloaded

kevinhermawan009kevinhermawan009 Member ✭✭
edited January 6 in Xamarin.Android
if (e.NewElement != null)
            {

                try
                {
                    var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
                    if (status != PermissionStatus.Granted)
                    {
                        if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Camera))
                        {
                           // await DisplayAlert("Need location", "Gunna need that location", "OK");
                        }

                        var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);
                        //Best practice to always check that the key exists
                        if (results.ContainsKey(Permission.Camera))
                            status = results[Permission.Camera];
                    }

                    if (status == PermissionStatus.Granted)
                    {
                        Control.Preview = Camera.Open((int)e.NewElement.Camera);
                    }
                    else if (status != PermissionStatus.Unknown)
                    {
                      // await DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
                    }
                }
                catch (Exception ex)
                {

                   // LabelGeolocation.Text = "Error: " + ex;
                }


                // Subscribe
                cameraPreview.Click += OnCameraPreviewClicked;
            }
        }
Tagged:

Answers

Sign In or Register to comment.