Android Auto - 如何取消已发送的通知

时间:2015-11-05 23:46:35

标签: android notifications android-auto

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

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自动不允许用户解雇通知,我该怎么办?

更新:我还试过以下:

    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);

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

0 个答案:

没有答案