Advertisement

Android 4.4.x 版本的通知功能中设置了删除意图失败

阅读量:

在项目开发过程中,需要对用户从状态栏中移除(通过滑动或点击X按钮关闭)通知的事件进行监控,但在Android 4.4.x版本的设备上,我们发现无法接收到与该操作相关的intent触发信号。

设置deleteIntent的代码如下:

Notification pushNotification = new Notification(
R.drawable.icon_notification, content,
System.currentTimeMillis());

Intent dIntent = new Intent(ACTION_IGNORE);
PendingIntent delIntent = PendingIntent.getBroadcast(mContext, 1,
dIntent, PendingIntent.FLAG_UPDATE_CURRENT);

pushNotification.deleteIntent = delIntent;
pushNotification.setLatestEventInfo(mContext, title, content,
contentIntent);

经过反复尝试和排查,最终在stackoverflow社区中找到了解决方法。将最后两句代码的位置进行调换,修改为:

p

全部评论 (0)

还没有任何评论哟~