//使用getSystemService(Context.NOTIFICATION_SERVICE)方法获取通知管理器
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//配置一个PendingIntent对象作为setContentIntent方法的参数
Intent intent = new Intent(this,DetailActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0);
//通过Buider构造一个通知对象
Notification notification = new NotificationCompat
//设置通知渠道id为11
.Builder(this, "11")
//设置通知标题
.setContentTitle("FBI Warning!")
//设置通知内容
//.setContentText("Learn how to build notifications, send and sync data, and use voice action. Get the official Android IDE and developer tools to build apps for Android.")
//以毫秒为单位获取当前系统时间
.setWhen(System.currentTimeMillis())
//设置在通知栏显示的小图标
.setSmallIcon(R.mipmap.ic_launcher)
//设置显示在通知的大图标
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
//设置延时Intent用于在用户点击通知时启动对应的组件
.setContentIntent(pendingIntent)
//设置用户点击通知后自动取消通知
.setAutoCancel(true)
//设置发出通知时播放的提示音
.setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luna.ogg")))
//设置手机在收到通知时震动提醒,使用一个长整型的数组控制震动时长和静止时长,第一个数值为静止时长,第二个数值为震动时长以此类推,单位为毫秒
.setVibrate(new long[]{0, 500, 1000, 500})
//设置当该通知未读时,锁屏状态下呼吸灯的闪烁颜色、亮起时间和熄灭时间,单位为毫秒
.setLights(Color.RED,1000,1000)
//设置让通知显示长文本内容
.setStyle(new NotificationCompat.BigTextStyle().bigText("Learn how to build notifications, send and sync data, and use voice action. Get the official Android IDE and developer tools to build apps for Android."))
//设置让通知显示一张图片
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)))
//设置通知的重要程度,共有五级min最小,max最大
.setPriority(NotificationCompat.PRIORITY_MAX)
.build();
//使用notify方法显示通知,同时设置该通知id为1
notificationManager.notify(1,notification);