2

在构建我的通知时,这不能取消通知:

NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(getApplicationContext())
                        .setSmallIcon(R.drawable.small_icon)
                        .setLargeIcon(largeIcon).setContentTitle(msg).setAutoCancel(true)
                        .setDefaults( Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS);
        ;

我想做的就是在用户查看通知后它应该自动取消。我还尝试立即取消通知,看看它是否可以从桌面主机取消,但它不起作用。我尝试了以下方法:

NotificationManagerCompat msgNotificationManager =
                NotificationManagerCompat.from(this);
        msgNotificationManager.cancel(myid);

这不会取消通知。当我使用设备时,这一切都很好,只是 android auto 不允许用户关闭通知,我该怎么做?

更新:我还尝试了以下方法:

    PendingIntent notifyPIntent =
                PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);

NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(getApplicationContext())
                        .setSmallIcon(R.drawable.small_icon)
                        .setLargeIcon(largeIcon).setContentTitle(msg).setAutoCancel(true)
                        .setDefaults( Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS)
                .setContentIntent(notifyPIntent);

但它没有帮助,同样的问题。

4

0 回答 0