android - NotificationCompat.InboxStyle 的添加行不起作用

标签 android android-intent notifications android-pendingintent

我正在尝试制作一个聊天应用程序,我的用户将在其中收到通知。通知量如此之大,如果我为每个通知创建一个条目,那么它会填满所有的地方,所以我想到应用 BigTextView 通知或 Stack of notifications。

我在下面写了一段代码:

NotificationManager notificationManager = (NotificationManager)
        this.getSystemService(Context.NOTIFICATION_SERVICE);
if(listMessage.size() <= 5)
listMessage.add(messagetype + ":" + msg);
else
{
     listMessage.remove(4);
     listMessage.add(messagetype + ":" + msg);
}
Intent notificationIntent = new Intent(this, GcmActivity.class);
notificationIntent.putExtra("title", messagetype);
notificationIntent.putExtra("message", msg);
PendingIntent intent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    NotificationCompat.Builder mBuilder;
        mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle("My MESSENGER")
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText("MESSAGES"))
                        .setContentText(msg)
                        .setAutoCancel(true)
                        .setLights(Color.WHITE, 1000, 5000)
                        .setDefaults(Notification.DEFAULT_VIBRATE |
                                Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
                        .setContentIntent(intent);

        NotificationCompat.InboxStyle inboxStyle =
                new NotificationCompat.InboxStyle();

        inboxStyle.setBigContentTitle("MESSAGES");
        for(int j= 0;j < listMessage.size();j++)
        {

            inboxStyle.addLine(listMessage.get(j));
        }

        mBuilder.setStyle(inboxStyle);
        notificationManager.notify(0, mBuilder.build());

这似乎没有在通知中添加行。它只显示 setContentText 并且什么都不显示。

最佳答案

您可能没有通知的展开 View 。 您需要在通知中向下滑动(用两根手指效果更好)。

关于android - NotificationCompat.InboxStyle 的添加行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288622/

相关文章:

java - Android 注册安全提供者

android - 如何计算 num_partition_sectors 和 start_sector 以从 android rom 的 system.img 创建 rawprogram0.xml 或 rawprogram_unsparse.xml?

java - 有没有办法用字符串以编程方式设置 View 的 id

java - 单击“保存”按钮时,editText 中的值不会更改

ios - 当应用程序未运行时处理推送通知(应用程序被杀死)

ios - iOS 中的不可移除通知以编程方式

android - GCM 注册设备接收两种类型的通知

android - 如何在android中发出警报时从挂起的 Intent 中获取requestCode

android - 在 res/drawable 文件夹中添加图像后,R.java 文件消失

ios - 安排无限数量的本地通知