首页 > 解决方案 > NotificationManager 使用清除所有通知

问题描述

是否可以清除所有通知?

btnMessageStyle1.setOnClickListener
           (arg0 -> {

         final int NOTIFICATION_ID = 1;
            mNotifyManager =
                    (NotificationManager) 
             getSystemService(Context.NOTIFICATION_SERVICE);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
               //                makeNotificationChannel("CHANNEL_1", "Example 
           channel", 
             NotificationManager.IMPORTANCE_DEFAULT);
                NotificationChannel channel = new 
              NotificationChannel("CHANNEL_1",
                        "Channel human readable title",
                        NotificationManager.IMPORTANCE_DEFAULT);
                mNotifyManager.createNotificationChannel(channel);
            }
            build = new NotificationCompat.Builder(getApplicationContext(), "CHANNEL_1");
            build.setContentTitle("Download")
                    .setContentText("Download in progress")
                    .setOngoing(true)
                    .setSmallIcon(R.drawable.jd)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                            R.mipmap.ic_launcher))
                    .setAutoCancel(true)
//                        .setContentIntent(resultPendingIntent)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setWhen(System.currentTimeMillis());

            mNotifyManager.notify(NOTIFICATION_ID, build.build());

                new Download().execute();
        });
    }

我尝试取消所有通知:

@Override
    public void onDestroy() {
       mNotifyManager.cancelAll();
        super.onDestroy();

    }

这个问题 如何在 Android解决方案中清除通知不适用于我的应用程序

标签: androidnotificationsandroid-notificationsandroid-notification-bar

解决方案


推荐阅读