title: Why NotificationManager notificationManager = (NotificationManager)GetSystemService(LocalNotificationService); shows an error?
body: <p>I am programming local notifications and I am creating <code>LocalNotificationService</code> and when I want to create <code>NotificationManager</code> It shows error at that line: </p>
  
  <pre><code>NotificationManager notificationManager =(NotificationManager)GetSystemService(LocalNotificationService);
  </code></pre>
  
  <p>Help me please! Thank you!
  Full code:</p>
  
  <p>[assembly: Xamarin.Forms.Dependency(typeof(LocalNotificationService))]       </p>
  
  <p>namespace Tyron.DependencyServices.Droid{       </p>
  
  <pre><code>public class LocalNotificationService : ILocalNotificationService       
  {       
      int _notificationIconId { get; set; }       
      readonly DateTime _jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);       
      internal string _randomNumber;
      public const string URGENT_CHANNEL = "main";
      public void LocalNotification(string title, string body, int id, DateTime notifyTime){       
  
          //long repeateDay = 1000 * 60 * 60 * 24;       
          long repeateForMinute = 86400000; // In milliseconds      
          long totalMilliSeconds = (long)(notifyTime.ToUniversalTime() - _jan1st1970).TotalMilliseconds;       
          if (totalMilliSeconds &lt; JavaSystem.CurrentTimeMillis()){       
              totalMilliSeconds = totalMilliSeconds + repeateForMinute;       
          }
  
  
  
          string chanName = "mainChanel";
          var importance = NotificationImportance.High;
          NotificationChannel chan = new NotificationChannel(URGENT_CHANNEL, chanName, importance);
          chan.EnableVibration(true);
          chan.LockscreenVisibility = NotificationVisibility.Public;
          NotificationManager notificationManager = (NotificationManager)GetSystemService(LocalNotificationService); // shows error: GetSystemService is not allowed at this context
          notificationManager.CreateNotificationChannel(chan);
          var intent = CreateIntent(id);       
          var localNotification = new LocalNotification();       
          localNotification.Title = title;       
          localNotification.Body = body;       
          localNotification.Id = id;       
          localNotification.NotifyTime = notifyTime;       
  
          if (_notificationIconId != 0){       
              localNotification.IconId = _notificationIconId;       
          }       
          else{       
              localNotification.IconId = Resource.Drawable.ic_mr_button_connecting_30_light;       
          }       
  
          var serializedNotification = SerializeNotification(localNotification);       
          intent.PutExtra(ScheduledAlarmHandler.LocalNotificationKey, serializedNotification);       
  
          Random generator = new Random();         
          _randomNumber = generator.Next(100000, 999999).ToString("D6");        
  
          var pendingIntent = PendingIntent.GetBroadcast(Application.Context, Convert.ToInt32(_randomNumber), intent, PendingIntentFlags.Immutable);       
          var alarmManager = GetAlarmManager();       
          alarmManager.SetRepeating(AlarmType.RtcWakeup, totalMilliSeconds, repeateForMinute, pendingIntent);       
      }
  
  
  
  
  
  
  
  
  
  
      public void Cancel(int id){       
  
          var intent = CreateIntent(id);       
          var pendingIntent = PendingIntent.GetBroadcast(Application.Context, Convert.ToInt32(_randomNumber), intent, PendingIntentFlags.Immutable);       
          var alarmManager = GetAlarmManager();       
          alarmManager.Cancel(pendingIntent);       
          var notificationManager = NotificationManagerCompat.From(Application.Context);       
          notificationManager.CancelAll();       
          notificationManager.Cancel(id);       
      }       
  
      public static Intent GetLauncherActivity(){       
  
          var packageName = Application.Context.PackageName;       
          return Application.Context.PackageManager.GetLaunchIntentForPackage(packageName);       
      }       
  
  
      private Intent CreateIntent(int id){       
  
          return new Intent(Application.Context, typeof(ScheduledAlarmHandler))       
              .SetAction("LocalNotifierIntent" + id);       
      }       
  
      private AlarmManager GetAlarmManager(){       
  
          var alarmManager = Application.Context.GetSystemService(Context.AlarmService) as AlarmManager;       
          return alarmManager;       
      }       
  
      private string SerializeNotification(LocalNotification notification){       
  
          var xmlSerializer = new XmlSerializer(notification.GetType());       
  
          using (var stringWriter = new StringWriter()){       
              xmlSerializer.Serialize(stringWriter, notification);       
              return stringWriter.ToString();       
          }       
      }       
  }       
  
  [BroadcastReceiver(Enabled = true, Label = "Local Notifications Broadcast Receiver")]       
  public class ScheduledAlarmHandler : BroadcastReceiver{       
  
      public const string LocalNotificationKey = "LocalNotification";       
  
      public override void OnReceive(Context context, Intent intent){       
          var extra = intent.GetStringExtra(LocalNotificationKey);       
          var notification = DeserializeNotification(extra);       
          //Generating notification       
          var builder = new NotificationCompat.Builder(Application.Context)       
              .SetContentTitle(notification.Title) 
              .SetChannelId("main")
              .SetContentText(notification.Body)       
              .SetSmallIcon(notification.IconId)       
              .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm))       
              .SetAutoCancel(true);       
  
          var resultIntent = LocalNotificationService.GetLauncherActivity();       
          resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);       
          var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(Application.Context);       
          stackBuilder.AddNextIntent(resultIntent);       
  
          Random random = new Random();       
          int randomNumber = random.Next(9999 - 1000) + 1000;        
  
          var resultPendingIntent =       
              stackBuilder.GetPendingIntent(randomNumber, (int)PendingIntentFlags.Immutable);       
          builder.SetContentIntent(resultPendingIntent);       
          // Sending notification       
          var notificationManager = NotificationManagerCompat.From(Application.Context);       
          notificationManager.Notify(randomNumber, builder.Build());       
      }       
  
      private LocalNotification DeserializeNotification(string notificationString){       
  
          var xmlSerializer = new XmlSerializer(typeof(LocalNotification));       
          using (var stringReader = new StringReader(notificationString))       
          {       
              var notification = (LocalNotification)xmlSerializer.Deserialize(stringReader);       
              return notification;       
          }       
      }
  
  
  
    /*  private void createNotificationChannel()
      {
          var channelName = "main";
          var channelDescription = "The main channel";
  
          // set the vibration patterm for the channel
          long[] vibrationPattern = { 100, 200, 300, 400, 500, 400, 300, 200, 400 };
  
          // Creating an Audio Attribute
          var alarmAttributes = new AudioAttributes.Builder()
                                 .SetContentType(AudioContentType.Sonification)
                                 .SetUsage(AudioUsageKind.Alarm)
                                 .Build();
  
          // Create the uri for the alarm file
          // Note: Make sure you add the mp3 file in your Android project under Resources/raw/soundFile.mp3 and set the build as Android Resource
          var alarmUri = Android.Net.Uri.Parse("MyApp.Android/Resources/raw/alarm.mp3");
  
  
          // create chan1  which is the urgent notifications channel
          var chan1 = new NotificationChannel(channelName, channelName, NotificationImportance.High)
          {
              Description = channelDescription
          };
  
  
          // set the channel properties
          chan1.EnableLights(true);
          chan1.LightColor = Color.Red;
          chan1.EnableVibration(true);
          chan1.SetVibrationPattern(vibrationPattern);
          chan1.SetSound(alarmUri, alarmAttributes);          // this is where the sound is set for the channel
          chan1.SetBypassDnd(true);
          chan1.LockscreenVisibility = NotificationVisibility.Public;
  
          // finally create the channel
          var manager = (NotificationManager)GetSystemService(NotificationService);
  
      }
      */
  }
  </code></pre>
  
  <p>}       </p>