Remove the notification icon from the status bar

后端 未结 4 994
说谎
说谎 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:22

    Intent resultIntent = new Intent(application, MainActivity.class);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(application, 0, resultIntent, 0);
    NotificationManager nmgr = (NotificationManager) application.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(application)
                .setSmallIcon(R.drawable.icon_battery)
                .setContentTitle(application.getString(R.string.app_name))
                .setContentText("your text")
                .setOnlyAlertOnce(false)
                .setAutoCancel(true)
                .setTicker("your ticker")
                .setDefaults(Notification.DEFAULT_SOUND  ) //| Notification.DEFAULT_VIBRATE
                .setContentIntent(resultPendingIntent)
                .setVisibility(VISIBILITY_SECRET)
                .setPriority(Notification.PRIORITY_MIN);
    
    Notification mNotification = mBuilder.build();
    //  mNotification.flags |= FLAG_NO_CLEAR;
    nmgr.notify(0, mNotification);
    

提交回复
热议问题