它会生成包含Gmail等多条消息的通知

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)

.setSmallIcon(R.drawable.quemark1)

.setContentTitle("Title")

.setContentText("New Message received");

NotificationCompat.InboxStyle inboxStyle =

new NotificationCompat.InboxStyle();

inboxStyle.setBigContentTitle("doUdo");

// Add your All messages here or use Loop to generate messages

inboxStyle.addLine("Messgare 1");

inboxStyle.addLine("Messgare 2");

.

.

inboxStyle.addLine("Messgare n");

mBuilder.setStyle(inboxStyle);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

stackBuilder.addNextIntent(intent);

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,

PendingIntent.FLAG_UPDATE_CURRENT);

mBuilder.setContentIntent(pIntent);

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

mBuilder.setAutoCancel(true);

mNotificationManager.notify(0, mBuilder.build());

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐