Android notification doesn't disappear after clicking the notifcation

前端 未结 7 692
逝去的感伤
逝去的感伤 2020-12-12 17:48

If got some issues with a notification I want to show in the notification bar. Although I set the notification flag to Notification.DEFAULT_LIGHTS & Notification.F

相关标签:
7条回答
  • 2020-12-12 18:22
    notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
    

    From the documentation:

    Bit to be bitwise-ored into the flags field that should be set if the notification should be canceled when it is clicked by the user

    0 讨论(0)
  • 2020-12-12 18:22
    // Uses the default lighting scheme
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    
    // Will show lights and make the notification disappear when the presses it
    notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
    
    0 讨论(0)
  • Use the flag Notification.FLAG_AUTO_CANCEL

    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
    
    // Cancel the notification after its selected
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    

    and to launch the app:

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    
    Intent intent = new Intent(context, App.class);
    
    PendingIntent pendingIntent = PendingIntent.getActivity(context, intent_id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    
    0 讨论(0)
  • 2020-12-12 18:23

    While building Notification by NotificationBuilder you can use notificationBuilder.setAutoCancel(true);.

    0 讨论(0)
  • 2020-12-12 18:33

    2016 state: you can use mBuilder.setAutoCancel(true).

    Source: https://developer.android.com/reference/android/app/Notification.Builder.html

    0 讨论(0)
  • 2020-12-12 18:34

    The answer for me was to use mBuilder.setOngoing(false)

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