nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification = new NotificationCompat.Builder(this, "12306")
.setContentTitle("系统通知")
.setContentText("世界这么大,好想出去走走!")
.setSmallIcon(R.drawable.ic_baseline_person_24)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.a5))
.setAutoCancel(true)
.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//Build.VERSION_CODES.O等于26
NotificationChannel channel = new NotificationChannel("12306", "muzi",
NotificationManager.IMPORTANCE_HIGH);
nManager.createNotificationChannel(channel);
}
public void sendNotification(View view) {
nManager.notify(1,notification);
}
|