title: How to use SetAction in Xamarin
body: <p>I'm trying to whitelist my app on Android 6.0 or greater. I have seen Android code to do this, but it doesn't translate in Xamarin and Xamarin documentation only tells you that SetAction takes a string as an argument, and then a link to Android documentation which doesn't end up being the same.</p>
  
  <p>Here's the Android code that Xamarin will not accept</p>
  
  <pre><code>intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
  </code></pre>
  
  <p>It doesn't like Settings. I've read the Xamarin documentation which says that SetAction() takes a string arg, and that's all they say and point you to Android documentation.</p>
  
  <p>Note, I am calling this in a javascript interface class and I tried this but it doesn't work</p>
  
  <pre><code>class MyJSInterface : Java.Lang.Object
      {
      Context context;
      public MyJSInterface(Context context)
          {
              this.context = context;
          }
      [Export]
      [JavascriptInterface]
      public void SetDozeOptimization()
          {
              Toast.MakeText(context, "launch optimization", ToastLength.Short).Show();
  
              setDozeComplete = false;
              Intent intent = new Intent();
              String packageName = context.PackageName;
              PowerManager pm = (PowerManager)context.GetSystemService(Context.PowerService);
              if (pm.IsIgnoringBatteryOptimizations(packageName))
                  intent.SetAction("ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS");
              else
              {
                  intent.SetAction("ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS");
                  intent.SetData(Android.Net.Uri.Parse("package:" + packageName));
              }
              context.StartActivity(intent);
          }
  
  }
  </code></pre>
  
  <p>So what is the correct syntax to accomplish this?</p>