public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
 {
     if (grantResults[0] == (int)Permission.Granted)
     {
         SetPermissions.OKResultHandler(requestCode);
     }
     else
     {
         SetPermissions.FailedResultHandler(requestCode);
     }
 }
 public void RequestPermissions(PermissionObject obj)
 {
     _PermissionTable.Add(obj);
     if (Has(obj) == false)
     {
         ActivityCompat.RequestPermissions(MainActivity, obj.Permissions, obj.ID);
     }
     else
     {
         SetPermissions.OKResultHandler(obj.ID);
     }
 }
            public override void OnDismissed(Snackbar snackbar, int evt)
            {
                if (evt == 2)
                {
                    System.Diagnostics.Debug.WriteLine("cancelled");
                    SetPermissions.FailedResultHandler(this.Parent.ID);
                }
                else
                {
                    ActivityCompat.RequestPermissions(Xamarin.Forms.Forms.Context as MainActivity, Parent.Permissions, Parent.ID);
                }

                base.OnDismissed(snackbar, evt);
            }
        public void RequestPermissionsReason(PermissionObject obj)
        {
            _PermissionTable.Add(obj);

            var c = Xamarin.Forms.Forms.Context;

            if (ContextCompat.CheckSelfPermission(c, obj.PermissionToTest) == (int)Android.Content.PM.Permission.Granted)
            {
                // granted permission ok
                SetPermissions.OKResultHandler(obj.ID);
            }
            else
            {
                if (String.IsNullOrEmpty(obj.Reason) == false)
                {
                    if (obj.AsPopup == false)
                    {
                        AlertDialog.Builder builder = new AlertDialog.Builder(Xamarin.Forms.Forms.Context as Activity);
                        builder.SetMessage(obj.Reason);
                        builder.SetPositiveButton("OK", (o, x) => {
                            ActivityCompat.RequestPermissions(MainActivity, obj.Permissions, obj.ID);
                        });
                        builder.SetNegativeButton("Cancel", (o, x) => {
                            SetPermissions.FailedResultHandler(obj.ID);
                        });
                        builder.Create();
                        builder.Show();
                    }
                    else
                    {
                        // snackbar implementation
                        Snackbar.Make(GetSnackbarAnchorView(), obj.Reason,
                                      (int)TimeSpan.FromSeconds(10).TotalMilliseconds)
                        .SetAction("OK", (x) => {
                        })
                        .SetCallback(new MySnackBarCallback(obj))
                        .Show();
                    }
                }
                else
                {
                    ActivityCompat.RequestPermissions(MainActivity, obj.Permissions, obj.ID);
                }
            }
        }