我目前正在研究
Android Support Package v4 Rev 10的NotificationCompat功能.
documentation表示’setContentText()’显示通知中的第二行.这适用于API 8直到API 15.但是,如果我尝试在API 16中使用此方法,我的通知将错过第二行.我只看到标题而不是第二行.添加多行是没有问题的(使用’addline()’).
这是我使用的NotificationCompat.Builder的代码:
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; }
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());
这是Jelly Bean的想要功能,setContentText被忽略还是我错过了什么?代码在没有错误的所有版本上运行,但我想添加第二行,使用与ICS或更早版本相同的代码.
我还添加了两个截图.第一个来自我的ICS 4.0.3华为MediaPad,第二个来自Galaxy Nexus和4.1.1.从1开始的第二行是简单的与通知标题相同的字符串.它在2不可见.
感谢您的帮助!