android - 为什么 Jelly Bean 不在通知中显示第二行?

标签 android notifications android-4.2-jelly-bean

我目前正在研究 Android 支持包 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 或更早版本上使用的相同代码。

我还添加了两个屏幕截图。第一个来 self 的 ICS 4.0.3 Huawei MediaPad,第二个来自 Galaxy Nexus 4.1.1。第二行来自1为简单起见,使用与通知标题相同的字符串。在 2 上不可见.

提前感谢您的帮助!

The ICS 4.0.3 device The JellyBean 4.1.1 device

最佳答案

Is this a wanted feature of Jelly Bean, that setContentText is ignored or am I missing something?

setContextText() 的值应该在折叠状态下可见(例如,如果展开,则两指向上滑动,或者它不是最顶层的 Notification).根据上面的代码,在展开状态下它将被替换为 NotificationCompat.InboxStyle

关于android - 为什么 Jelly Bean 不在通知中显示第二行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11988073/

相关文章:

android - 正确使用Android SQLiteStatement的simpleQueryForBlobFileDescriptor()

java - 在 android 中使用 java 代码创建 Android 布局

android - 如何使用 Notification.deleteIntent

Android JB 广播接收器不接收 bluetooth.android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED

android - 在 Visual Studio 中构建 Xamarin.Android 时 GetAdditionalResourcesFromAssemblies 错误

java - Imageview 没有显示我的图像?

rest - 带通知的 PayPal REST API

android - Pushwoosh - native Android - 不接收通知

android - 在 Android 4.2 的 StateListDrawable 中使用默认的 ShapeDrawable

android - 无法在设备上调试 Android 4.1 上的应用程序