【Android】监听Notification被清除
正文: |
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent == null || context == null) { return; } mNotificationManager.cancel(NOTIFICATION_ID_LIVE); String type = intent.getStringExtra(PUSH_TYPE); if (PUSH_TYPE_LINK.equals(type)) { //mNumLinkes = 0; } else if (PUSH_TYPE_LIVE.equals(type)) { //mNumLives = 0; } //这里可以重新计数 } }; private void sendLiveNotification() { Intent intent = new Intent(NOTIFICATION_CLICK_ACTION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); String title = "Push测试"; mBuilder.setContentTitle(title); mBuilder.setTicker(title); mBuilder.setContentText("https://233.tv/over140"); mBuilder.setLargeIcon(BitMapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); mBuilder.setSmallIcon(R.drawable.ic_action_cast); mBuilder.setDefaults(Notification.DEFAULT_ALL); mBuilder.setWhen(System.currentTimeMillis()); mBuilder.setContentIntent(PendingIntent.getBroadcast(this, NOTIFICATION_ID_LIVE, intent, 0)); mBuilder.setDeleteIntent(PendingIntent.getBroadcast(this, NOTIFICATION_ID_LIVE, new Intent(NOTIFICATION_DELETED_ACTION).putExtra(PUSH_TYPE, PUSH_TYPE_LIVE), 0)); mNotificationManager.notify(NOTIFICATION_ID_LIVE, mBuilder.build()); }
代码说明
创新互联公司自2013年创立以来,是专业互联网技术服务公司,拥有项目网站建设、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元思茅做网站,已为上家服务,为思茅各地企业和个人服务,联系电话:13518219792
1、最重要的是setDeleteIntent,这个在API Level 11(Android 3.0) 新增的
2、注意不要设置setAutoCancel为true,否则监听器接收不到
3、这里统一了点击通知和消除通知的操作
4、注意广播在推送前要注册好
文章题目:【Android】监听Notification被清除
新闻来源:http://ybzwz.com/article/jehpog.html