Android的通知意向将其清除自身 [英] Android Notification intent to clear it self

查看:87
本文介绍了Android的通知意向将其清除自身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了如何创建通知消息的例子很多。 我想要的东西来实现,是因为该通知将通过一个小部件来执行,我想 通知意图时点击时,用户点击它。我不具有活性,返回到以清除它自己。 通知我的目的只是清楚地告知,没有别的。 那么,什么将是刚刚疏通/取消自身意图的code。 在code以下是通过一个按钮启动(不包括按钮code)该通知将通过一个后台服务被解雇了。一个活动

I have read many examples of how to create notification messages. What i wanted to achieve, is because the notification will be executed by a widget, i would like the notification intent when clicked to clear it self when the user clicks on it.I do not have an activity to return to. The notification for my purposes will just plainly notify, nothing else. So what would be the code of an intent that just clear/cancel itself. The code below is an activity launched by a button(button code not included) the notification will be fired up by a background service.

CharSequence title = "Hello";
CharSequence message = "Hello, Android!";
final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);

感谢

推荐答案

查看<一个href="http://developer.android.com/intl/de/reference/android/app/Notification.html#FLAG_AUTO_CANCEL">FLAG_AUTO_CANCEL

位进行按位或为它被点击时,用户应设置在通知应取消标志字段。

Bit to be bitwise-ored into the flags field that should be set if the notification should be canceled when it is clicked by the user.

编辑:

notification.flags |= Notification.FLAG_AUTO_CANCEL;

这篇关于Android的通知意向将其清除自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆