Cancel notification on remove application from multitask panel

前端 未结 7 1721
北恋
北恋 2020-11-27 14:15

I manage an ONGOING notification from my application (not from a service).

When I kill application from task manager with \"End\" button, no

相关标签:
7条回答
  • 2020-11-27 15:21

    I wanted to close all my App notifications,remove badge icons on Logout, removed from recent app list . so for

    Xamarin.Android

    start service at launcher activity(i am creating notification from here) as

    Intent intent = new Intent(this, typeof(PushNotificationService));
    this.StartService(intent);
    

    where PushNotificationService is my Android service inside which i have

    [Service]
        public class PushNotificationService : Service
            {
                public override IBinder OnBind(Intent intent)
                {
                    return null;
                }
    
            public override void OnCreate()
            {
                base.OnCreate();
            }
            public override void OnTaskRemoved(Intent rootIntent)
            {
                try
                {
                    var notificationManager = (NotificationManager)GetSystemService(NotificationService);
                    notificationManager.Cancel(0);
                    ME.Leolin.Shortcutbadger.ShortcutBadger.RemoveCount(Application.Context);
                }
                catch (System.Exception ex)
                {
                }
            }
        }
    

    this line in OnTaskRemoved(Intent rootIntent) did the trick

     var notificationManager = (NotificationManager)GetSystemService(NotificationService);
                    notificationManager.Cancel(0);
    

    where 0 in notificationManager.Cancel(0); is the local notifcation id which we put at the time of building notification.

    0 讨论(0)
提交回复
热议问题