How to get context of ActivityCompat.RequestPermissions

dai15002dai15002 Member ✭✭

In my Xamarin.Form I call a function inside MainActivity to grant permission for WRITE_CALENDAR. However I need to get the right context to be passed in ActivityCompat.RequestPermissions funtion. My solution:

 public bool GrantPermission()
    {

        if (hasPermission)
        {
            // We have permission
            return true;
        }
        else
        {
            int RC_REQUEST_PERMISSION = 1000;
            string[] REQUIRED_PERMISSIONS = { Android.Manifest.Permission.WriteCalendar };

            // USING this WILL CRASH
            ActivityCompat.RequestPermissions(this, REQUIRED_PERMISSIONS, RC_REQUEST_PERMISSION);

        }


        return false;

    }

How can I get an working activity context to send inside ActivityCompat.RequestPermissions?

Posts

  • dai15002dai15002 Member ✭✭

    fixed by changing this to CrossCurrentActivity.Current.Activity

Sign In or Register to comment.