【问题标题】:Android : Unable to display multiple lines of text in NotificationAndroid:无法在通知中显示多行文本
【发布时间】:2014-01-30 06:33:45
【问题描述】:

我试图在通知中使用BigTextStyle 显示多行文本,但无法这样做。我正在使用下面的代码。

public void sendNotification(View view) {
    String msgText = "Jeally Bean Notification example!! "
            + "where you will see three different kind of notification. "
            + "you can even put the very long string here.";

    NotificationManager notificationManager = getNotificationManager();
    PendingIntent pi = getPendingIntent();
    android.app.Notification.Builder builder = new Notification.Builder(
            this);
    builder.setContentTitle("Big text Notofication")
            .setContentText("Big text Notification")
            .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
            .setPriority(Notification.PRIORITY_HIGH)
            .addAction(R.drawable.ic_launcher, "show activity", pi);
    Notification notification = new Notification.BigTextStyle(builder)
            .bigText(msgText).build();

    notificationManager.notify(0, notification);
}

public NotificationManager getNotificationManager() {
    return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

public PendingIntent getPendingIntent() {
    return PendingIntent.getActivity(this, 0, new Intent(this,
            MainActivity.class), 0);
}

我什至在通知中都看不到“msgText”。知道为什么吗? 感谢您的帮助。

【问题讨论】:

    标签: android notifications notificationmanager


    【解决方案1】:

    解决了!

    代码很好,只是没有足够的空间进行大通知。当我断开数据线时,它以所需的方式显示。 :-)

    感谢所有试图提供帮助的人。

    【讨论】:

    • 有什么方法可以在默认情况下以完全展开模式显示通知,而不是双指展开。谢谢
    • 您的代码对我不起作用。你有什么改变吗?它只是在一行中显示文本,删除尾随文本。
    • @AnandPrakash ,如答案中所述,只需断开电缆。
    【解决方案2】:

    只需将通知样式设置为 BigText

       NotificationCompat.BigTextStyle bigStyle =
       new NotificationCompat.BigTextStyle();
       bigStyle.setBigContentTitle(title);
       bigStyle.bigText(messageBody);
       builder.setStyle(bigStyle);
    

    【讨论】:

      【解决方案3】:

      也尝试设置内容意图值。

      Notification.Builder builder = new Notification.Builder(this);
      builder.setContentTitle("Big text Notification")
              .setContentText("Big text Notification")
              .setSmallIcon(R.drawable.ic_launcher)
              .setAutoCancel(true)
      
              .setContentIntent(pi) // <- this new line
      
              .setPriority(Notification.PRIORITY_HIGH)
              .addAction(R.drawable.ic_launcher, "show activity", pi);
      

      【讨论】:

        【解决方案4】:

        .setPriority(Notification.PRIORITY_HIGH) - 这一行解决了我的问题。多行保存大小。

        【讨论】:

        • 优先级与developer.android.com/reference/android/app/…“此通知的相对优先级无关。优先级表示该通知应消耗多少用户的宝贵注意力。低优先级通知可能是在某些情况下对用户隐藏,而用户可能会因更高优先级的通知而被打断。系统将在呈现通知时确定如何解释此优先级。”
        • 你永远不应该使用优先级来修复一些错误。优先权是为了优先权。阅读文档
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 2018-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-26
        • 1970-01-01
        相关资源
        最近更新 更多