title: Requesting Android permissions in a class (Xamarin)
body: <p>I'm trying to request a permission at runtime for my app. I use a service provider to talk between the portable class and Android. </p>
  
  <p>I start by calling this code on button press in the PCL:</p>
  
  <pre><code>using (new Busy(this))
                  {
                      var locationHelper = scope.Resolve&lt;ILocationHelper&gt;();
                      locationHelper.GetLocation(this);
                  }
  </code></pre>
  
  <p>This calls my Android level service:</p>
  
  <pre><code>public class AndroidLocationHelper : ILocationHelper, ILocationListener
      {
  
          readonly string[] PermissionsLocation =
          {
              Manifest.Permission.AccessCoarseLocation
          };
          const int RequestLocationId = 0;
  
  public void GetLocation(SearchViewModel viewModel)
          {
              try
              {
                  const string permission = Manifest.Permission.AccessCoarseLocation;
                  if (((int)Build.VERSION.SdkInt &lt; 23) || (CheckSelfPermission(permission) == Permission.Granted))
                  {
                  }
                  else
                      RequestPermissions(PermissionsLocation, RequestLocationId);
              }
              catch (Exception ex)
              {
                  Debug.WriteLine("Error while getting Location service");
                  Debug.WriteLine(ex.Message);
                  Messaging.AlertUser("There was an error with determining your location");
              }
          }
  </code></pre>
  
  <p>However, I get two errors on <code>CheckSelfPermission</code> and <code>RequestPermissions</code>. These two methods are only available to activities. The code works fine in <code>MainActivity</code>; however, I want to ask for permissions when the user hits a button, not in <code>OnCreate</code> or <code>OnResume</code>, etc.</p>
  
  <p>Thanks for any help.</p>