private async Task UpdateProgress() { NotificationManagerCompat nm = NotificationManagerCompat.From(this); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, ChannelId) .SetContentTitle(GetString(Resource.String.notificationTitle)) .SetContentText(GetString(Resource.String.notificationDesc)) .SetSmallIcon(Resource.Drawable.ic_stat_name) .SetProgress(100, 0, false) .SetOngoing(true) .SetPriority(-1); nm.Notify(NotificationId, builder.Build()); while (isWorking) { if (Progress == 100) { builder.SetProgress(100, 100, false); nm.CancelAll(); Log(Type.Event, "Finished work, stopping service..."); isWorking = false; StopSelf(); } builder.SetProgress(100, Progress, false); nm.Notify(NotificationId, builder.Build()); await Task.Delay(1000); } }
public void Hide() { if (notificationManager != null) { notificationManager.CancelAll(); } }
public MediaNotificationManager(MusicService service) { callback.Parent = this; Service = service; UpdateSessionToken(); NotificationManager = NotificationManagerCompat.From(service); var pkg = service.PackageName; pauseIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPause).SetPackage(pkg), PendingIntentFlags.CancelCurrent); playIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPlay).SetPackage(pkg), PendingIntentFlags.CancelCurrent); previousIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPrevious).SetPackage(pkg), PendingIntentFlags.CancelCurrent); nextIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionNext).SetPackage(pkg), PendingIntentFlags.CancelCurrent); stopCastingIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionStopCasting).SetPackage(pkg), PendingIntentFlags.CancelCurrent); NotificationManager.CancelAll(); }
internal static void StopNotification(Context context) { NotificationManagerCompat nm = NotificationManagerCompat.From(context); nm.CancelAll(); }
public void StopNotifications() { NotificationManagerCompat nm = NotificationManagerCompat.From(_appliactionContext); nm.CancelAll(); }
public void StopNotification() { NotificationManagerCompat nm = NotificationManagerCompat.From(this.ApplicationContext); nm.CancelAll(); }
public void StopNotification() { NotificationManagerCompat notificationManager = NotificationManagerCompat.From(ApplicationContext); notificationManager?.CancelAll(); }
public MediaNotificationManager(MusicService serv) { service = serv; UpdateSessionToken(); notificationColor = ResourceHelper.GetThemeColor(service, Android.Resource.Attribute.ColorPrimary, Color.DarkGray); notificationManager = NotificationManagerCompat.From(service); string pkg = service.PackageName; pauseIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPause).SetPackage(pkg), PendingIntentFlags.CancelCurrent); playIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPlay).SetPackage(pkg), PendingIntentFlags.CancelCurrent); previousIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionPrev).SetPackage(pkg), PendingIntentFlags.CancelCurrent); nextIntent = PendingIntent.GetBroadcast(service, RequestCode, new Intent(ActionNext).SetPackage(pkg), PendingIntentFlags.CancelCurrent); notificationManager.CancelAll(); mCb.OnPlaybackStateChangedImpl = (state) => { playbackState = state; LogHelper.Debug(Tag, "Received new playback state", state); if (state.State == PlaybackStateCompat.StateStopped || state.State == PlaybackStateCompat.StateNone) { StopNotification(); } else { Notification notification = CreateNotification(); if (notification != null) { notificationManager.Notify(NotificationId, notification); } } }; mCb.OnMetadataChangedImpl = (meta) => { metadata = meta; LogHelper.Debug(Tag, "Received new metadata ", metadata); Notification notification = CreateNotification(); if (notification != null) { notificationManager.Notify(NotificationId, notification); } }; mCb.OnSessionDestroyedImpl = () => { LogHelper.Debug(Tag, "Session was destroyed, resetting to the new session token"); try { UpdateSessionToken(); } catch (Exception e) { LogHelper.Error(Tag, e, "could not connect media controller"); } }; }