Android- 多行通知

Android- Multiple line notification

因为我想发出多行通知而不是一行,所以我使用 BigTextStyle()。实际上,它不能正常工作。它像正常通知一样工作。

这是我的代码:

NotificationManager notificationManager = (NotificationManager)
        context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.icon);
mBuilder.setContentTitle("Messenger");
mBuilder.setContentText(message);
NotificationCompat.InboxStyle inboxStyle =
        new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");

// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {

    inboxStyle.addLine(events[i]);
}
mBuilder.setStyle(inboxStyle);

Intent notificationIntent = new Intent(context, CustomMainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
mBuilder.setContentIntent(intent);
notificationManager.notify(1, mBuilder.build());

我认为您使用的样式不对。尝试像这样使用 NotificationCompat.BigTextStyle .setStyle(new NotificationCompat.BigTextStyle().bigText("your text goes here...))