android 通知栏的Intent事件

来源:互联网 发布:汽车零部件进出口数据 编辑:程序博客网 时间:2024/06/03 20:04
 //获取管理器
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);builder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(msg);
if (intent != null) {    builder.setContentIntent(PendingIntent.getActivity(context, id, intent, 0));    Log.e("233", "showNotification: " + intent.getIntExtra("action", 10086));}manager.notify(id, builder.build());
这样就可以显示一个最简单的通知栏
PendingIntent.getActivity(context, id, intent, 0)
中id的那个是requestCode 请求代码。这个不写重复的,否侧之后你的Intent中带的参数将会无法传递至
你跳转的Activity中。

原创粉丝点击