public override void OnDestroy() { // We need to shut things down. //Log.Info(Tag, "OnDestroy: The started service is shutting down."); // Remove the notification from the status bar. NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this); notificationManager.Cancel(ServiceRunningNotificationId); _activityCommon.SetLock(ActivityCommon.LockType.None); DisconnectEdiabasEvents(); lock (ActivityCommon.GlobalLockObject) { EdiabasThread ediabasThread = ActivityCommon.EdiabasThread; if (ediabasThread != null) { ediabasThread.ActiveContext = null; } } _activityCommon.Dispose(); _activityCommon = null; _isStarted = false; if (_stopHandler != null) { _stopHandler.Dispose(); _stopHandler = null; } base.OnDestroy(); }
protected override async void OnResume() { base.OnResume(); Log(Type.Info, "OnResume started"); bool fromNotification = Intent.HasExtra("NotificationSong"); if (fromNotification) { Log(Type.Event, "Attempting to load song from notification"); Analytics.TrackEvent("Opening song from notification", new Dictionary <string, string> { { "NotificationSong", JsonConvert.SerializeObject(notificationSong) } }); notificationSong = JsonConvert.DeserializeObject <SongBundle>(Intent.GetStringExtra("NotificationSong") !); NotificationManagerCompat ntfManager = NotificationManagerCompat.From(this); ntfManager.Cancel(NotificationId); songInfo = notificationSong; previousNtfSong = notificationSong; shouldCheck = false; nowPlayingMode = true; LoadSong(); } }
public override void OnDestroy() { // We need to shut things down. //Log.Info(Tag, "OnDestroy: The started service is shutting down."); // Remove the notification from the status bar. NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this); notificationManager.Cancel(ServiceRunningNotificationId); if (_wakeLockCpu != null) { try { _wakeLockCpu.Release(); _wakeLockCpu.Dispose(); } catch (Exception) { // ignored } _wakeLockCpu = null; } _activityCommon.Dispose(); _activityCommon = null; _isStarted = false; base.OnDestroy(); }
private void unScheduleNotification(string notificationId, AlarmManager alarmManager, NotificationManagerCompat notificationManager) { var scheduledNotificationIntent = new Intent(Application.Context, typeof(SmartAlertCalendarEventBroadcastReceiver)); scheduledNotificationIntent.SetData(getSmartAlertIdentifierUri(notificationId.GetHashCode())); notificationManager.Cancel(notificationId.GetHashCode()); cancelExistingPendingIntentIfNecessary(notificationId.GetHashCode(), scheduledNotificationIntent, alarmManager); }
public override void OnDestroy() { Binder = null; nmc.Cancel(10000); StopSelf(); StopForeground(true); Log.Debug("CountService", "OnDestroy - Stop foreground service"); base.OnDestroy(); }
private async void HandleChosenSong(Song chosen) { if (chosen.Likeness >= MaxLikeness) { Log(Type.Info, $"Selected song {chosen.Title} by {chosen.Artist} with likeness {chosen.Likeness} is too unlikely.\n Song not found."); ntfManager.Cancel(NotificationId); } else if (string.IsNullOrEmpty(chosen.Title)) { Log(Type.Info, "Song not found!"); ntfManager.Cancel(NotificationId); } else if (chosen.Likeness <= MaxLikeness) { Log(Type.Event, $"Selected song is {chosen.Title} by {chosen.Artist} with likeness {chosen.Likeness}."); if (!MiscTools.IsInForeground()) { CreateNotification(new SongBundle(chosen, new RomanizedSong())); } } }
public void Cancel(int id) { Intent intent = CreateIntent(id); PendingIntent pendingIntent = PendingIntent.GetBroadcast(AndroidApp.Context, 0, intent, PendingIntentFlags.CancelCurrent); AlarmManager alarmManager = GetAlarmManager(); alarmManager.Cancel(pendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.From(AndroidApp.Context); notificationManager.Cancel(id); }
public void StopNotification() { if (started) { started = false; controller.UnregisterCallback(mCb); try { notificationManager.Cancel(NotificationId); service.UnregisterReceiver(this); } catch (ArgumentException) { // ignore if the receiver is not registered. } service.StopForeground(true); } }
public void StopNotification() { if (!started) { return; } started = false; controller.UnregisterCallback(callback); try { NotificationManager.Cancel(NotificationId); Service.UnregisterReceiver(this); } catch (IllegalArgumentException ex) { } Service.StopForeground(true); }
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { if (!deadNotification && !thirstyNotification && !hungryNotification) { nmc = NotificationManagerCompat.From(this); nmc.Cancel(1000); countHungry = 30; countThirsty = 100; Log.Debug("CountService", "OnStartCommand - Start Service Notification"); h = new Handler(); h.Looper.Thread.Name = "CountService"; h.Post(this); SendMyNotification(Resources.GetString(Resource.String.app_name), "Start Service", "service_notification", "service_notification", "start service notification", true); } return(StartCommandResult.Sticky); }
private void CloseLocalNotification() { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.From(Current.Activity); notificationManagerCompat.Cancel((int)NotificationsEnum.NewMessageReceived); }
private void CloseLocalNotification() { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.From(Current.Activity); notificationManagerCompat.Cancel(LocalNotificationsManager.NotificationId); }
public static async Task CreateNotifications(LocationData location, List <WeatherAlert> alerts) { // Gets an instance of the NotificationManager service NotificationManagerCompat mNotifyMgr = NotificationManagerCompat.From(App.Context); InitChannel(); // Create click intent // Start WeatherNow Activity with weather data Intent intent = new Intent(App.Context, typeof(MainActivity)) .SetAction(Widgets.WeatherWidgetService.ACTION_SHOWALERTS) .PutExtra("data", location.ToJson()) .PutExtra(Widgets.WeatherWidgetService.ACTION_SHOWALERTS, true) .SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask | ActivityFlags.ClearTask); PendingIntent clickPendingIntent = PendingIntent.GetActivity(App.Context, 0, intent, 0); // Build update foreach (WeatherAlert alert in alerts) { var alertVM = new WeatherAlertViewModel(alert); var iconBmp = ImageUtils.TintBitmap( await BitmapFactory.DecodeResourceAsync(App.Context.Resources, GetDrawableFromAlertType(alertVM.AlertType)), Color.Black); var title = String.Format("{0} - {1}", alertVM.Title, location.name); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(App.Context, NOT_CHANNEL_ID) .SetSmallIcon(Resource.Drawable.ic_error_white) .SetLargeIcon(iconBmp) .SetContentTitle(title) .SetContentText(alertVM.ExpireDate) .SetStyle(new NotificationCompat.BigTextStyle().BigText(alertVM.ExpireDate)) .SetContentIntent(clickPendingIntent) .SetOnlyAlertOnce(true) .SetAutoCancel(true) .SetPriority(NotificationCompat.PriorityDefault) as NotificationCompat.Builder; if (Build.VERSION.SdkInt < BuildVersionCodes.N) { // Tell service to remove stored notification mBuilder.SetDeleteIntent(GetDeleteNotificationIntent((int)alertVM.AlertType)); } if (Build.VERSION.SdkInt >= BuildVersionCodes.N || WeatherAlertNotificationService.GetNotificationsCount() >= MIN_GROUPCOUNT) { mBuilder.SetGroup(TAG); } // Builds the notification and issues it. // Tag: location.query; id: weather alert type if (Build.VERSION.SdkInt < BuildVersionCodes.N) { WeatherAlertNotificationService.AddNotication((int)alertVM.AlertType, title); } mNotifyMgr.Notify(location.query, (int)alertVM.AlertType, mBuilder.Build()); } bool buildSummary = false; if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { try { NotificationManager mNotifyMgrV23 = (NotificationManager)App.Context.GetSystemService(App.NotificationService); var statNotifs = mNotifyMgrV23.GetActiveNotifications(); if (statNotifs?.Length > 0) { buildSummary = statNotifs.Count(not => location.query.Equals(not.Tag)) >= MIN_GROUPCOUNT; } } catch (Exception ex) { Logger.WriteLine(LoggerLevel.Debug, ex, "SimpleWeather: {0}: error accessing notifications", LOG_TAG); } } else { buildSummary = WeatherAlertNotificationService.GetNotificationsCount() >= MIN_GROUPCOUNT; } if (buildSummary) { // Notification inboxStyle for grouped notifications var inboxStyle = new NotificationCompat.InboxStyle(); if (Build.VERSION.SdkInt < BuildVersionCodes.N) { // Add active notification titles to summary notification foreach (var notif in WeatherAlertNotificationService.GetNotifications()) { mNotifyMgr.Cancel(location.query, notif.Key); inboxStyle.AddLine(notif.Value); } inboxStyle.SetBigContentTitle(App.Context.GetString(Resource.String.title_fragment_alerts)); inboxStyle.SetSummaryText(location.name); } else { inboxStyle.SetSummaryText(App.Context.GetString(Resource.String.title_fragment_alerts)); } NotificationCompat.Builder mSummaryBuilder = new NotificationCompat.Builder(App.Context, NOT_CHANNEL_ID) .SetSmallIcon(Resource.Drawable.ic_error_white) .SetContentTitle(App.Context.GetString(Resource.String.title_fragment_alerts)) .SetContentText(location.name) .SetStyle(inboxStyle) .SetGroup(TAG) .SetGroupSummary(true) .SetContentIntent(clickPendingIntent) .SetOnlyAlertOnce(true) .SetAutoCancel(true) as NotificationCompat.Builder; if (Build.VERSION.SdkInt < BuildVersionCodes.N) { mSummaryBuilder.SetDeleteIntent(GetDeleteAllNotificationsIntent()); } // Builds the summary notification and issues it. mNotifyMgr.Notify(location.query, SUMMARY_ID, mSummaryBuilder.Build()); } }
public void StopNotifications() { NotificationManagerCompat nm = NotificationManagerCompat.From(_applicationContext); nm.Cancel(_notificationId); }