目录
Notification
NotificationBuilder
Notification
private void showNotification() {
Notification notification=new Notification();//初始化notification
notification.icon= R.mipmap.ic_launcher;//设置通知的图片
notification.tickerText="我是一个消息";//设置状态栏的文本
notification.flags=Notification.FLAG_AUTO_CANCEL;//设置为 可以取消
Intent intent=new Intent(getApplicationContext(),MainActivity.class);//设置pendingIntent事件
PendingIntent pend=PendingIntent.getActivity(getApplicationContext(),1, intent, PendingIntent.FLAG_ONE_SHOT);//设置pendingInten使用方式
notification.setLatestEventInfo(getApplicationContext(),"我是一个标题","我是内容",pend);
notification.when=System.currentTimeMillis();//设置显示通知的时间
mNotificationManager.notify(1,notification); //将通知发送给id为1的用户
}

NotificationBuilder
private void showNotificationBuilder() {
Intent intent=new Intent(getApplicationContext(),MainActivity.class);//设置pendingIntent事件
PendingIntent pend=PendingIntent.getActivity(getApplicationContext(),1, intent, PendingIntent.FLAG_ONE_SHOT);//设置pendingInten使用方式
Notification notification=new Notification.Builder(MainActivity.this).setSmallIcon(R.mipmap.ic_launcher).setTicker("我是一条消息").setContentTitle("我是标题")
.setContentText("我是文本吧").setContentInfo("我是消息").setShowWhen(true).setAutoCancel(true).build();
mNotificationManager.notify(2,notification);
}