通知类型
1.普通通知
2.列表通知
3.大图通知
4.进度条通知
5.自定义通知
普通通知

private void normal() {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher_background);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_background);
builder.setLargeIcon(bitmap);
builder.setTicker("你收到一条短信息请注意查收");
builder.setContentTitle("短信");
builder.setContentText("你好我是短信息");
builder.setContentInfo("我是附加消息");
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setAutoCancel(true);
Notification build = builder.build();
manager.notify(1, build);
}
列表通知

private void list() {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.mipmap.ee);
builder.setContentTitle("我是列表数据");
builder.setContentText("123132");
Notification.InboxStyle style = new Notification.InboxStyle();
style.addLine("我是第一行");
style.addLine("我是第二行");
style.addLine("我是第三行");
style.addLine("我是第四行");
builder.setStyle(style);
manager.notify(5, builder.build());
}
大图通知

private void big() {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.mipmap.ee);
builder.setContentTitle("我是大图数据");
builder.setContentText("123132");
Notification.BigPictureStyle style = new Notification.BigPictureStyle();
style.bigPicture(BitmapFactory.decodeResource(getResources(), R.mipmap.u));
builder.setStyle(style);
manager.notify(5, builder.build());
}
进度条通知


private void progess() {
final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.mipmap.ee);
builder.setContentTitle("我是水平通知");
builder.setContentText("123132");
builder.setProgress(100, progress, false);
CountDownTimer countDownTimer = new CountDownTimer(11000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
progress += 10;
builder.setProgress(100, progress, false);
manager.notify(3, builder.build());
}
@Override
public void onFinish() {
}
}.start();
manager.notify(3, builder.build());
}
自定义通知

private void customer() {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
builder.setSmallIcon(R.mipmap.ee);
builder.setContentTitle("我是自定义通知的标题");
builder.setContentText("123132");
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.sim);
remoteViews.setTextViewText(R.id.textnotification, "我是自定义通知的文本");
remoteViews.setImageViewResource(R.id.imgnotification, R.mipmap.u);
builder.setContent(remoteViews);
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 200, intent, PendingIntent.FLAG_ONE_SHOT);
builder.setContentIntent(pendingIntent);
manager.notify(2, builder.build());
}
