Why doesn't Jelly Bean show the second line in the notification?

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!

The ICS 4.0.3 deviceThe JellyBean 4.1.1 device

+8
android notifications android-4.2-jelly-bean
source share
3 answers

Is this the desired Jelly Bean function that setContentText is ignored or am I missing something?

The value of setContextText() should be visible when folded (for example, when double-dragging with two fingers, if it is not the topmost Notification ). It will be replaced by NotificationCompat.InboxStyle in advanced state, given your code above.

+7
source share

If you want to show the default notification in extended state. Just set PRIORITY_MAX for the builder. It seems like: builder.setPriority (Notification.PRIORITY_MAX);

+1
source share

I fixed this problem now using @CommonsWare's help and created a simple method that checks the current API level and decides which command to use:

 private void createCompatibleSecondLine(CharSequence pTitle, NotificationCompat.Builder pBuilder, InboxStyle pInboxStyle) { // set the text for pre API 16 devices (or for expanded) if (android.os.Build.VERSION.SDK_INT < 16) { pBuilder.setContentText(pTitle); } else { pInboxStyle.setSummaryText(pTitle); } } 

So it’s nothing wild and far from perfect, but he does the job for me. Improvements are always welcome :)

0
source share

All Articles