1。首先创建一个NotificationManage对通知进行管理,并且调用getSystemService()获取实例
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
2.需要使用Buider()构建器来创建Notification对象
Intent intent = new Intent(MainActivity.this,NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0, intent,0);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("通知")
.setContentText("你的彩票中奖了").
setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher_round).
setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher_round))
.setContentIntent(pi)
.setVibrate(new long[] {0,1000,1000,1000})
.setLights(Color.RED,1000,5000)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.build();
manager.notify(1,notification);