I am currently studying the NotificationCompat functions of the Android v4 Rev 10. Support Package. The documentation says that 'setContentText ()' shows the second line in the notification. This is true for API 8 through API 15. However, if I try to use this method in API 16, my notifications will skip the second line. I see only the title, but not the second line. Adding multiple lines is not a problem (using "addline ()").
Here is my code for NotificationCompat.Builder, which I used:
private NotificationCompat.Builder buildNormal(CharSequence pTitle) { NotificationCompat.Builder builder = new NotificationCompat.Builder( getSherlockActivity()); builder.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL); // set the shown date builder.setWhen(System.currentTimeMillis()); // the title of the notification builder.setContentTitle(pTitle); // set the text for pre API 16 devices builder.setContentText(pTitle); // set the action for clicking the notification builder.setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)); // set the notifications icon builder.setSmallIcon(android.R.drawable.stat_sys_download_done); // set the small ticker text which runs in the tray for a few seconds builder.setTicker("This is your ticker text."); // set the priority for API 16 devices builder.setPriority(Notification.PRIORITY_DEFAULT); return builder; }
And if I want to add a few lines and show a notification, I use this code:
NotificationCompat.Builder normal = buildNormal("This is an Expanded Layout Notification."); NotificationCompat.InboxStyle big = new NotificationCompat.InboxStyle( normal); // summary is below the action big.setSummaryText("this is the summary text"); // Lines are above the action and below the title big.addLine("This is the first line").addLine("The second line") .addLine("The third line").addLine("The fourth line"); NotificationManager manager = getNotificationManager(normal); manager.notify(Constants.NOTIFY_ID, big.build());
Is it a necessary Jelly Bean function that setContentText is ignored or am I missing something? The code works on all versions without errors, but I would like to add a second line with the same code that I use in ICS or earlier.
I also added two screenshots. the first of my ICS 4.0.3 is Huawei MediaPad and the second is from Galaxy Nexus with 4.1.1. The second line of 1 is for simplicity of the same line as the name of the notification. It does not appear at 2 .
Thanks for your help in advance!


android notifications android-4.2-jelly-bean
Markus rudel
source share