Remove the notification icon from the status bar

后端 未结 4 995
说谎
说谎 2020-12-01 15:07

I am displaying an icon in status bar.Now I want to remove that icon immediately when I open that content, after some time if we receive any alert, that icon will be display

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 15:31

    I used the Builder patter so you can just set auto cancel from the setter setAutoCancel(true). That looks something like this:

        String title = "Requests"; 
        String msg = "New requests available.";
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_gcm_icon)
                        .setContentTitle(title)
                        .setAutoCancel(true)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(msg))
                        .setContentText(msg);
    
        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    

提交回复
热议问题