我创建了一个通知,但是一旦我点击它,它就不会被删除!我甚至尝试过notification.setAutoCancel(true)和notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL
下面是我的代码:
notification.setSmallIcon(R.drawable.message64);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.setSound(uri);
Resources resources = getApplicationContext().getResources(),
systemResources = Resources.getSystem();
notification.setTicker("Notification");
notification.setContentTitle("Nouveau message");
notification.setContentText("Vous avez reçu un nouveau message. ");
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(uniqueID,notification.build());它工作得很好,但当我点击它时,它仍然不能删除它。
发布于 2018-02-02 16:31:16
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setWhen(System.currentTimeMillis())
.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher))
.setContentTitle(getString(R.string.app_name))
.setAutoCancel(true)
.setContentText("Test")
getManager().notify(ID, builder.build());使用setAutoCancel(true)是否在单击时清除通知
https://stackoverflow.com/questions/48578222
复制相似问题