Notification.Builder的使用

 1                 NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);//获取系统服务
 2                 Notification noti = new Notification.Builder(MainActivity.this)//实例化Builder
 3                  .setTicker("sdhsajdsaj")//在状态栏显示的标题
 4                  .setWhen(java.lang.System.currentTimeMillis())//设置显示的时间,默认就是currentTimeMillis()
 5                  .setContentTitle("New mail from ")//设置标题
 6                  .setContentText("111")//设置内容
 7                  .setSmallIcon(R.drawable.ic_launcher)//设置状态栏显示时的图标
 8                  .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))//设置显示的大图标
 9                  .setContentIntent(PendingIntent.getActivity(MainActivity.this, 0, new Intent(Settings.ACTION_SETTINGS), 0))//设置点击时的意图
10                  .setDeleteIntent(PendingIntent.getActivity(MainActivity.this, 0, new Intent(Settings.ACTION_SETTINGS), 0))//设置删除时的意图
11                  .setFullScreenIntent(PendingIntent.getActivity(MainActivity.this, 0, new Intent(Settings.ACTION_SETTINGS), 0), true)//这个将直接打开意图,而不经过状态栏显示再按下
12                  .setAutoCancel(false)//设置是否自动按下过后取消
13                  .setOngoing(true)//设置为true时就不能删除  除非使用notificationManager.cancel(1)方法
14                  .build();//创建Notification
15                notificationManager.notify(1, noti);//管理器通知
原文地址:https://www.cnblogs.com/ZSS-Android/p/3994987.html