![](/img/trans.png)
[英]Is it possible to clear the Notification when using android.support.v4.app.NotificationCompat.mBuilder.addAction
[英]How do i cancel notification using mBuilder.addAction
我想在通知上添加取消按钮 。 点击该按钮,我想从通知栏中删除我的通知。 有没有办法做到这一点,或者我是以错误的方式做到这一点。
noti=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder=new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.and);
mBuilder.setContentTitle("Downloading");
mBuilder.setContentText("Downloading in progress");
mBuilder.addAction(R.drawable.and,"cancil",);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_ONE_SHOT);
//Button as addAction is deprecated use this one.
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.mipmap.ic_launcher, "Cancel", pendingIntent).build();
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Back to Application ?")
.setContentTitle("Amazing news")
.addAction(action) //add buton
.build();
//Send notification
NotificationManager notificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.