由于我想制作多行通知而不是一行我正在使用 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());
答案 0 :(得分:0)
我认为你使用的风格是错误的风格。尝试使用NotificationCompat.BigTextStyle,如.setStyle(new NotificationCompat.BigTextStyle().bigText("your text goes here...))