我的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