问题描述
我已经创建与API版本按钮超过16个。
I have created a notification with a button for API versions more than 16.
通知和按钮都正确来了。我想解雇点击按钮或通知的通知。
Notification and button are coming up properly. I would like to dismiss the notification on clicking the button or notification.
在单击通知显示通知被清除,但是当我点击按钮,它不会做任何事情是不一样的。
On clicking the notification the notificiation gets cleared but it is not the same when I click on the button it doesn't do anything.
我不知道怎么听按钮,点击通知?有人可以帮我解决这个问题?
I am not sure how to listen to button click on Notification? Can somebody help me fix this?
看截图......所以当我点击AndroidProject - 通知被清除,一个意图相应地调用,但是当我点击关闭或红色的X标志的通知仍然存在,只是意图被调用。如何实现以清除通知,当我点击关闭或X按钮?
Look at the screen shot... So when I click on AndroidProject - The notification is cleared and an intent is called accordingly, but when I click on Close or the red X mark notification is still there but intent is called. How do I implement to clear notification when I click on the close or X button?
下面是我曾尝试:
Intent notificationIntent = new Intent(context, ServicetocancelAlarm.class);
PendingIntent contentIntent = PendingIntent.getService(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Resources res = context.getResources();
Notification noti = new Notification.Builder(context)
.setContentTitle(res.getString(R.string.app_name))
.setContentText(res.getString(R.string.cancelText))
.setSmallIcon(R.drawable.ic_launcher)
.setTicker(res.getString(R.string.ticker))
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.addAction(R.drawable.cancel, "DISMISS", contentIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
谢谢!
推荐答案
当你打电话通知的通知经理,你给它一个id - 这是唯一ID,您可以使用更高版本来访问它(这是从通知经理
When you called notify on the notification manager you gave it an id - that is the unique id you can use to access it later (this is from the notification manager:
notify(int id, Notification notification)
有关取消
cancel(int id)
阅读以下链接: -
read below link:-
Dismiss正在进行Android通知通过操作按钮不打开应用
这篇关于在Android通知按钮的onClick监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!