我目前正在研究
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不可见.
感谢您的帮助!
解决方法
Is this a wanted feature of Jelly Bean,that setContentText is ignored or am I missing something?
setContextText()的值应该在折叠状态下可见(例如,如果展开,则双指向上滑动,或者它不是最顶层的通知).在给定上面的代码的情况下,它将在展开状态下由NotificationCompat.InboxStyle替换.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。