当我滑动时没有删除android推送通知

Gan*_*ghe 2 android

当我滑动时没有删除android推送通知

以下是我尝试实现推送通知的代码

 NotificationCompat.Builder mBuilder =
                        new NotificationCompat.Builder(context)
                        .setSmallIcon(icon)
                        .setContentTitle(title)
                        .setAutoCancel(true)
                        .setContentText(message)
                        .setOngoing(true);


            Intent notificationIntent = new Intent(context, MainActivity.class);
            notificationIntent.putExtra("Your Message", message);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            notificationIntent.putExtra("type", type);
            notificationIntent.putExtra("id", id);
            PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(intent);

            notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这些问题吗

Ski*_*ᴉʞS 6

.setOngoing(true);应该是假的,或者只是删除这一行,如果你不把.setOngoing(boolean)它会是假的,那么你就可以刷卡的通知。

更多信息 setOnGoing

设置这是否是“正在进行的”通知。用户无法取消正在进行的通知,因此您的应用程序或服务必须注意取消它们。它们通常用于指示用户正在积极参与(例如,播放音乐)或以某种方式挂起并因此占用设备(例如,文件下载、同步操作、活动网络连接)的后台任务。

所以你mBuilder应该像:

NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(context)
                    .setSmallIcon(icon)
                    .setContentTitle(title)
                    .setAutoCancel(true)
                    .setContentText(message)
                    .setOngoing(false); //or just remove it
Run Code Online (Sandbox Code Playgroud)