参考:https://blog.csdn.net/hgy413/article/details/88539924
// 通知与提醒
Intent stateIntent = new Intent(this, MusicButtonActivity.class);
PendingIntent statePendingIntent = PendingIntent.getActivity(this, 0, stateIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this, "FCM_foreground")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("标题")//设置内容标题
.setContentText("内容")//设置显示的内容
.setContentIntent(statePendingIntent)//设置意图
.setDefaults(NotificationCompat.FLAG_ONLY_ALERT_ONCE)// 只通知1次
.setSound(null) // 不发出声音
.setPriority(Notification.PRIORITY_HIGH) // 优先级高
.setAutoCancel(true);//点击后消失
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManagerCompat.notify((int) 123, mBuilder.build());
其他可看资料:
https://blog.csdn.net/shanshui911587154/article/details/105683683
https://juejin.im/post/6844903911409762317
https://blog.csdn.net/qi85481455/article/details/82895507?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.pc_relevant_is_cache&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.pc_relevant_is_cache