Android Notification intent to clear it self

前端 未结 6 1436
旧巷少年郎
旧巷少年郎 2020-12-09 08:25

I have read many examples of how to create notification messages. What i wanted to achieve, is because the notification will be executed by a widget, i would like the notifi

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 09:01

    If you're using NotificationCompat.Builder (a part of android.support.v4) then simply call its object's method setAutoCancel

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setAutoCancel(true);
    

    Some guys were reporting that setAutoCancel() did not work for them, so you may try this way as well

    builder.build().flags |= Notification.FLAG_AUTO_CANCEL;
    

提交回复
热议问题