Android 通知 - 显示完整消息

标签 android google-cloud-messaging

我的 Android 应用程序必须能够向一大群人发送简短的警报。显而易见的地方是在通知中心。完整的通知毫无问题地显示在代码中,但在通知中心,用户只能看到前几个单词,然后是省略号。通知一点也不长,最多只有10-15个字。如何让文本换行换行?

我构建通知的代码在这里

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.splash)
    .setContentTitle("Student Engauge")
    .setContentText(extras.getString("message"))
    .setAutoCancel(true)
    .setTicker(extras.getString("message"));
    final int notificationId = 1;
    NotificationManager nm = (NotificationManager) getApplicationContext()
          .getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificationId, mBuilder.build());

最佳答案

要显示大量文本,请使用 BigTextStyle。这是 BigTextStyle 中给出的示例代码.此通知将包含一行文本,如果需要,将扩展到更多行。

Notification noti = new Notification.Builder()
 .setContentTitle("New mail from " + sender.toString())
 .setContentText(subject)
 .setSmallIcon(R.drawable.new_mail)
 .setLargeIcon(aBitmap)
 .setStyle(new Notification.BigTextStyle()
     .bigText(aVeryLongString))
 .build();

对于安卓支持库

Notification noti = new Notification.Builder()
 .setContentTitle("New mail from " + sender.toString())
 .setContentText(subject)
 .setSmallIcon(R.drawable.new_mail)
 .setLargeIcon(aBitmap)
 .setStyle(new NotificationCompat.BigTextStyle()
     .bigText(aVeryLongString))
 .build();

关于Android 通知 - 显示完整消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16470583/

相关文章:

android - 如何在 Android Studio 中向现有项目添加新 Activity ?

java - 单元测试Android功能

java - 延迟数据导致 OnCreate 上出现 NullPointerException

android - GCM 如何注销设备与 GCM 和第 3 方服务器

Azure 通知中心 - 从 GCM 迁移到 FCM

android - Android 上的缓慢 HttpPost 请求

android - 如何在应用程序内更改语言(区域设置)后刷新 Activity

Android 推送通知 - 如何获取设备 ID

android - 谷歌云消息 : registration_ids vs. 设备组

android - 如果 Android 用户在设置中禁用了我的应用程序的推送通知,我的应用程序是否仍会静默接收它们?