В настоящее время я изучаю функции NotificationCompat пакета поддержки Android v4 Rev 10. В документации говорится, что '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 Huawei MediaPad и второй от Galaxy Nexus с 4.1.1. Вторая строка из 1 для простоты представляет собой ту же строку, что и заголовок уведомления. На 2 его не видно.
Заранее спасибо за помощь!