private void NotificationAdapterViewHolder_ItemLongClicked(object sender, Notificaciones.NotificationEventArgs.NotificationItemClickedEventArgs e) { position = e.Position; using (OpenNotification openNotification = new OpenNotification(e.Position)) { if (openNotification.IsRemovable()) { using (NotificationSlave notificationSlave = NotificationSlave.NotificationSlaveInstance()) { if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { int notiId = CatcherHelper.statusBarNotifications[position].Id; string notiTag = CatcherHelper.statusBarNotifications[position].Tag; string notiPack = CatcherHelper.statusBarNotifications[position].PackageName; notificationSlave.CancelNotification(notiPack, notiTag, notiId); } else { notificationSlave.CancelNotification(CatcherHelper.statusBarNotifications[position].Key); } } floatingNotificationView.Visibility = ViewStates.Gone; } } }
private void BtnClearAll_Click(object sender, EventArgs e) { using (NotificationSlave notificationSlave = NotificationSlave.NotificationSlaveInstance()) { notificationSlave.CancelAll(); } }
public void ClickNotification() { try { CatcherHelper.statusBarNotifications[position].Notification.ContentIntent.Send(); //Android Docs: For NotificationListeners: When implementing a custom click for notification //Cancel the notification after it was clicked when this notification is autocancellable. if (IsRemovable()) { using (NotificationSlave notificationSlave = NotificationSlave.NotificationSlaveInstance()) { if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { int notiId = CatcherHelper.statusBarNotifications[position].Id; string notiTag = CatcherHelper.statusBarNotifications[position].Tag; string notiPack = CatcherHelper.statusBarNotifications[position].PackageName; notificationSlave.CancelNotification(notiPack, notiTag, notiId); } else { notificationSlave.CancelNotification(CatcherHelper.statusBarNotifications[position].Key); } } } } catch { Console.WriteLine("Click Notification failed, fail in pending intent"); } }
private void ItemLongClicked(object sender, NotificationItemClickedEventArgs e) { position = e.Position; notification.Visibility = ViewStates.Visible; using (OpenNotification openNotification = new OpenNotification(e.Position)) { //If the notification is removable... if (openNotification.IsRemovable()) { //Then remove the notification using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance()) { if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { int notiId = CatcherHelper.statusBarNotifications[position].Id; string notiTag = CatcherHelper.statusBarNotifications[position].Tag; string notiPack = CatcherHelper.statusBarNotifications[position].PackageName; slave.CancelNotification(notiPack, notiTag, notiId); } else { slave.CancelNotification(CatcherHelper.statusBarNotifications[position].Key); } } notification.Visibility = ViewStates.Invisible; titulo.Text = null; texto.Text = null; notificationActions.RemoveAllViews(); } } }
public override bool OnOptionsItemSelected(IMenuItem item) { int id = item.ItemId; switch (id) { case Resource.Id.action_settings: using (Intent intent = new Intent(this, typeof(SettingsActivity))) { intent.AddFlags(ActivityFlags.NewDocument); StartActivity(intent); } return(true); case Resource.Id.action_sendtestnotification: if (isApplicationHealthy) { using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance()) { var notificationtext = Resources.GetString(Resource.String.testnotificationtext); if (Build.VERSION.SdkInt > BuildVersionCodes.NMr1) { slave.PostNotification("LiveDisplay", notificationtext, true, NotificationImportance.Low); } else { slave.PostNotification("LiveDisplay", notificationtext, true, NotificationPriority.Low); } } using (Intent intent = new Intent(Application.Context, typeof(LockScreenActivity))) { StartActivity(intent); return(true); } } else { Toast.MakeText(Application.Context, "You dont have the required permissions yet", ToastLength.Long).Show(); } break; case Resource.Id.action_help: using (Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this)) { builder.SetMessage(Resource.String.helptext); builder.SetPositiveButton("ok, cool", null as EventHandler <DialogClickEventArgs>); builder.Show(); } break; default: break; } return(base.OnOptionsItemSelected(item)); }
public void OnNotificationPosted(StatusBarNotification sbn) { //This is the notification of 'LiveDisplay is showing above other apps' //Simply let's ignore it, because it's annoying. (Anyway, the user couldn't care less about this notification tbh) if (sbn.PackageName == "android" && sbn.Tag == "com.android.server.wm.AlertWindowNotification - com.underground.livedisplay") { return; } var blockingstatus = Blacklist.ReturnBlockLevel(sbn.PackageName); if (!blockingstatus.HasFlag(LevelsOfAppBlocking.Blacklisted)) { if (!blockingstatus.HasFlag(LevelsOfAppBlocking.BlockInAppOnly)) { int index = GetNotificationPosition(sbn); //Tries to get the index of a possible already existing notification in the list of notif. if (index >= 0) { //It exists within the list. //SO it should be updated. StatusBarNotifications.RemoveAt(index); StatusBarNotifications.Add(sbn); using (var h = new Handler(Looper.MainLooper)) h.Post(() => { notificationAdapter.NotifyItemChanged(index); }); OnNotificationPosted(blockingstatus.HasFlag(LevelsOfAppBlocking.None), sbn, true); } else { StatusBarNotifications.Add(sbn); using (var h = new Handler(Looper.MainLooper)) h.Post(() => { notificationAdapter.NotifyItemInserted(StatusBarNotifications.Count); }); OnNotificationPosted(blockingstatus.HasFlag(LevelsOfAppBlocking.None), sbn, false); } } } else { var notificationSlave = NotificationSlave.NotificationSlaveInstance(); if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch) { notificationSlave.CancelNotification(sbn.Key); } else { notificationSlave.CancelNotification(sbn.PackageName, sbn.Tag, sbn.Id); } } if (StatusBarNotifications.Count > 0) { OnNotificationListSizeChanged(new NotificationListSizeChangedEventArgs { ThereAreNotifications = true }); } }
public void OnItemLongClick(int position) { if (Catcher.listaNotificaciones[position].IsClearable == true) { int notiId = Catcher.listaNotificaciones[position].Id; string notiTag = Catcher.listaNotificaciones[position].Tag; string notiPack = Catcher.listaNotificaciones[position].PackageName; NotificationSlave slave = new NotificationSlave(); slave.CancelNotification(notiPack, notiTag, notiId); v.Visibility = ViewStates.Invisible; } else { Toast.MakeText(Application.Context, "No", ToastLength.Short).Show(); } }
public void Cancel() { if (IsRemovable()) { using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance()) { if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { slave.CancelNotification(GetPackageName(), GetTag(), GetId()); } else { slave.CancelNotification(GetKey()); } } } }
public void Cancel() { if (IsRemovable()) { using (NotificationSlave slave = NotificationSlave.NotificationSlaveInstance()) { //If this notification has a mediacontroller callback registered we unregister it, to avoid leaks. if (mediaController != null) { mediaController.UnregisterCallback(MusicController.GetInstance()); } if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { slave.CancelNotification(GetPackageName(), GetTag(), GetId()); } else { slave.CancelNotification(GetKey()); } } } }
public void OnNotificationPosted(OpenNotification sbn) { if (sbn == null) { return; } //This is the notification of 'LiveDisplay is showing above other apps' //Simply let's ignore it, because it's annoying. (Anyway, the user couldn't care less about this notification tbh) if (sbn.GetPackage() == "android" && sbn.GetTag() == "com.android.server.wm.AlertWindowNotification - com.underground.livedisplay") { return; } if (sbn.IsSummary()) { return; //Ignore the summary notification. (it causes redundancy) anyway, In an ideal scenario I should hide this notification instead } //of ignoring it. var blockingstatus = Blacklist.ReturnBlockLevel(sbn.GetPackage()); if (!blockingstatus.HasFlag(LevelsOfAppBlocking.Blacklisted)) { if (!blockingstatus.HasFlag(LevelsOfAppBlocking.BlockInAppOnly)) { bool causesWakeUp = false; if (sbn.GetNotificationPriority() >= (int)NotificationPriority.Default) //Solves a issue where non important notifications also turn on screen. //anyway this is a hotfix, a better method shoudl be used to improve the blacklist/the importance of notifications. { causesWakeUp = true; } else { causesWakeUp = false; } int index = GetNotificationPosition(sbn); //Tries to get the index of a possible already existing notification in the list of notif. if (index >= 0) { //It exists within the list. //SO it should be updated. StatusBarNotifications.RemoveAt(index); StatusBarNotifications.Add(sbn); using (var h = new Handler(Looper.MainLooper)) h.Post(() => { notificationAdapter.NotifyItemChanged(index); }); OnNotificationPosted(false, sbn, true); } else { StatusBarNotifications.Add(sbn); using (var h = new Handler(Looper.MainLooper)) h.Post(() => { notificationAdapter.NotifyItemInserted(StatusBarNotifications.Count); }); OnNotificationPosted(causesWakeUp, sbn, false); } } } else { var notificationSlave = NotificationSlave.NotificationSlaveInstance(); if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch) { notificationSlave.CancelNotification(sbn.GetKey()); } else { notificationSlave.CancelNotification(sbn.GetPackage(), sbn.GetTag(), sbn.GetId()); } } OnNotificationListSizeChanged(new NotificationListSizeChangedEventArgs { ThereAreNotifications = StatusBarNotifications.Count > 0 }); }