1. 为Notification添加点击事件(点击推送消息后发送广播)

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);    CharSequence tickerText = "test_title";    Notification notification = new Notification(R.drawable.notification, tickerText, System.currentTimeMillis());    notification.flags = Notification.FLAG_AUTO_CANCEL;    CharSequence contentTitle = "contentTitle";    CharSequence contentText = "contentText";    Intent notificationIntent = null;    notificationIntent = new Intent("NmTest");    PendingIntent contentIntent = PendingIntent.getBroadcast(Context, action, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);    notification.setLatestEventInfo(Context, contentTitle, contentText, contentIntent);    notificationManager.notify(notifiId, notification);

2. 注册广播接收器监听点击行为

registerReceiver(new BroadcastReceiver() {    @Override    public void onReceive(Context context, Intent intent) {        Log.d(TAG, "通知被点击!");    }}, new IntentFilter("NmTest"));

注:在发送消息时,一定要设置PendingIntentAction不同,否则会发生如下情况:
  当发出多条 action 和category 相同的推送之后,随便点击一条通知,广播接收器里面收到的 intent 里面拿出来的数据都是后面发送的那条。
相似问题:http://blog.csdn.net/z1074971432/article/details/17532139

更多相关文章

  1. 使用Android消息机制实现点击开始计数和暂停计数
  2. android 监听 USB 拔插广播消息
  3. 疯狂android讲义---事件处理2
  4. Android中如何使用基于监听的事件处理(上)
  5. android点击事件的四种方式
  6. Android 同时监听多个Button事件
  7. android亮屏、暗屏、解锁、关闭系统对话的监听事件

随机推荐

  1. Android开发之Activity(二)——启动模式和t
  2. 【Android】报表、线图、饼图、柱状图 (
  3. Android (Notification)消息推送机制
  4. Android 7.1 隐藏底部状态栏 和去掉默认
  5. android textview 点击变字
  6. 如何设置Android中TextView的行间距
  7. Android 启动项 Activity
  8. Android(安卓)UI控件之CheckBox实现墨迹
  9. android 虚拟机下面 安装apk文件
  10. android 监听系统时区变化,日期变化,时间变