1. 基本通知方式
private void sendNotification(){
int notificationId = 222;
String channelId = "channel_name";
String channelName = getPackageName();
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//创建NotificationChannel
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
manager.createNotificationChannel(channel);
Notification.Builder builder =new Notification.Builder(this, channelId);
builder.setContentText("This is Content Text");
builder.setContentTitle("This is title");
builder.setChannelId(channelId);//创建通知时指定channelID
builder.setColor(Color.GREEN);//SmallIcon color
builder.setSmallIcon(R.drawable.ic_launcher_background);
Notification notification = builder.build();
manager.notify(notificationId, notification);
}