1.定义notification
private NotificationCompat.Builder mBuilder;
mBuilder = new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(R.drawable.a)
.setContentTitle("")
.setContentText("");
2.添加点击notification跳转至activity
private Intent i_notifi;
private PendingIntent pi;
i_notifi = new Intent(this,MainActivity.class);
pi = PendingIntent.getActivity(this, 0, i_notifi, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pi);
3.启动notification
private NotificationManager nm;
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(001, mBuilder.build());
PS:点击notification后自动取消通知栏
mBuilder.setAutoCancel(true);
4.设置notification 显示多文字
Notification notif = new Notification.Builder(mContext)
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
参考