我目前正在寻找到Android的支持包V4版本10. documentation说,'setContentText()'示出了在通知中的第二行。这是API 8真正达到API 15。但是,如果我尝试用这种方法在API 16我的通知将错过第二行。我只看到标题,但不是第二行。添加多个行是没有问题的(利用'addline()')
下面是我的code为我所用的NotificationCompat.Builder:
私人NotificationCompat.Builder buildNormal(CharSequence的pTitle){ NotificationCompat.Builder建设者=新NotificationCompat.Builder( getSherlockActivity()); builder.setAutoCancel(真).setDefaults(Notification.DEFAULT_ALL); //设置显示日期 builder.setWhen(System.currentTimeMillis的()); //通知的标题 builder.setContentTitle(pTitle); //设置pre API 16台设备的文本 builder.setContentText(pTitle); //设置行动点击通知 builder.setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)); //设置图标的通知 builder.setSmallIcon(android.R.drawable.stat_sys_download_done); //设置它运行在托盘几秒钟,小股票的文字 builder.setTicker(这是你的股票的文字。); //设置优先级为API 16台设备 builder.setPriority(Notification.PRIORITY_DEFAULT); 返回建设者;}
如果我想添加多行,并显示该通知,我用这个code:
NotificationCompat.Builder正常= buildNormal(这是一个扩展的布局通知); NotificationCompat.InboxStyle大=新NotificationCompat.InboxStyle( 正常); //摘要的作用下 big.setSummaryText(这是摘要文本); //线是上方的动作和标题下方 big.addLine(这是第一行)。addLine(第二行) .addLine(第三线)addLine(第四线)。 NotificationManager经理= getNotificationManager(正常); manager.notify(Constants.NOTIFY_ID,big.build());
这是果冻豆的通缉的特点,那setContentText被忽略还是我失去了一些东西?在code上的所有版本没有错误运行,但我想用相同的code我在ICS使用添加第二个行或更早版本。
我还添加了两个截图。从我的ICS 4.0.3华为MediaPad的第一和从Galaxy Nexus的第二4.1.1。从 1 第二行是为了简单起见,相同的字符串作为通知的标题。这不是在 2 可见。
感谢您的帮助提前!
解决方案
这是果冻豆的通缉的特点,那setContentText被忽略还是我失去了一些东西?
的 setContextText()
应该是在折叠状态下可见的(例如,双指轻扫了,如果扩大,或有它不是最顶层的通知)。它将由 NotificationCompat.InboxStyle
在扩展状态下进行更换,给您code以上。
I'm currently looking into the NotificationCompat features of the Android Support Package v4 Rev 10. The documentation says that 'setContentText()' shows the second row in a notification. This is true for API 8 up to API 15. However, if I try to use this method in API 16 my Notifications will miss the second line. I see only the Title but not the second line. Adding multiple lines is no problem (using 'addline()').
Here's my code for the NotificationCompat.Builder 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 multiple lines and show the notification, I uses 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 this a wanted feature of Jelly Bean, that setContentText is ignored or am I missing something? The code runs on all versions without errors, but I would like to add the second line with the same code I use on ICS or earlier.
I've also added two screenshots. the first from my ICS 4.0.3 Huawei MediaPad and the second from a Galaxy Nexus with 4.1.1. The second line from 1 is for simplicity the same String as the notification title. It is not visible on 2.
Thanks for your help in advance!
解决方案
Is this a wanted feature of Jelly Bean, that setContentText is ignored or am I missing something?
The value of setContextText()
should be visible in the collapsed state (e.g., two-finger swipe up if expanded, or have it not be the top-most Notification
). It will be replaced by NotificationCompat.InboxStyle
in the expanded state, given your code above.
上一篇:我无法从我的Android模拟器删除日文输入法我的、日文、模拟器、输入法
下一篇:在标签布局投掷地图视图,java.lang.IllegalStateException:活页夹已经敲定,未捕获的异常引发的终结活页夹、视图、布局、异常