在这里,我将消息显示到自定义通知中,但我无法使其可扩展。如果我显示长文本消息,它会从末尾被截断。 目前为止,我已经尝试了很多方法,例如:
Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mBuilder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New message from " + chatContacts.getName())
.setContentText("")
.setLargeIcon(icon)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setStyle(new NotificationCompat.InboxStyle()
.setBigContentTitle("" + message)
.setSummaryText("New message from " + chatContacts.getName()))
.setContentIntent(contentIntent);
} else if (Build.VERSION_CODES.M >= Build.VERSION_CODES.KITKAT) {
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
String[] events = new String[6];
inboxStyle.setBigContentTitle("Event tracker details:");
inboxStyle.addLine(message);
mBuilder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(chatContacts.getName())
.setAutoCancel(true)
.setStyle(inboxStyle)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent);
} else {
mBuilder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setCustomBigContentView(contentView)
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setContentIntent(contentIntent);
}
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText(message);
mBuilder.setStyle(bigText);
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, mBuilder.build());