在清单文件中注册
<receiver
android:name=“.NotificationClickReceiver”>
在你需要创建通知栏的地方
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder1 = new Notification.Builder(MainActivity.this);
builder1.setSmallIcon(R.drawable.ic_launcher); //设置图标
builder1.setTicker(“显示第二个通知”);
builder1.setContentTitle(“通知”); //设置标题
builder1.setContentText(“点击查看详细内容”); //消息内容
builder1.setWhen(System.currentTimeMillis()); //发送时间
builder1.setDefaults(Notification.DEFAULT_ALL); //设置默认的提示音,振动方式,灯光
builder1.setAutoCancel(true);//打开程序后图标消失
Intent intent =new Intent (MainActivity.this,NotificationClickReceiver.class);
PendingIntent pendingIntent =PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
builder1.setContentIntent(pendingIntent);
Notification notific