在service里发送notification并传递参数

我的service是常驻service 在service里定义一个常量 int count =0;

  public void showNotification(String nearestMinor){
       Notification.Builder builder = new Notification.Builder(this);
       Intent mIntent = new Intent(this, TatgetActivity.class);
       Bundle bundle=new Bundle();
       bundle.putInt("count",1);
       mIntent.putExtras(bundle);

       PendingIntent pendingIntent = PendingIntent.getActivity(this, count, mIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
       builder.setContentIntent(pendingIntent);
       builder.setSmallIcon(R.drawable.default_face);
       builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.default_face));
       builder.setAutoCancel(true);
       builder.setContentTitle("悬挂式通知");
       builder.setVisibility(Notification.VISIBILITY_SECRET);
       builder.setContentText("nearestMinor="+nearestMinor);
       //设置点击跳转
//        Intent hangIntent = new Intent();
//        hangIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        hangIntent.setClass(this, TestActivity.class);
       //如果描述的PendingIntent已经存在,则在产生新的Intent之前会先取消掉当前的
       PendingIntent hangPendingIntent = PendingIntent.getActivity(this, 0, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
       builder.setFullScreenIntent(hangPendingIntent, true);

       NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
       nm.notify(0, builder.build());
       count++;
   }

传不同的count才能传递参数 应该是这样。。。

据说

Intent.FLAG_ACTIVITY_CLEAR_TOP
的设定页很关键

感谢这个哥们的demo!!!

http://blog.csdn.net/itachi85/article/details/50096609

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值