//创建一个notification
Notification.Builder builder = new Notification.Builder(this);
//通知第一次收到的时候在状态栏里显示的消息
builder.setTicker("你好吗?");
//点击就会消失
builder.setAutoCancel(true);
//通知栏显示的大标题
builder.setContentTitle("通知");
//通知栏显示的小的文本内容
builder.setContentText("你吃了吗");
//通知栏显示的小图标
builder.setSmallIcon(R.drawable.ic_launcher_background);
//点击不会消失 一般用于音乐播放器,下载栏
// builder.setOngoing(true);
//点击跳转
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(1, notification);
网友评论