简体   繁体   English

NotificationCompat.BigTextStyle内容在新通知上消失

[英]NotificationCompat.BigTextStyle Content disappears on new notification

    String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns);
        int icon = R.drawable.ic_launcher;
        CharSequence tickerText = title;
        long when = System.currentTimeMillis();             


        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if(alarmSound == null){
              alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            if(alarmSound == null){
                alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            }
        }           

        Intent intent = new Intent();
        PendingIntent pendingIntent 
        = PendingIntent.getActivity(this, 0, intent, 0);    

        NotificationCompat.BigTextStyle bigxtstyle =
        new NotificationCompat.BigTextStyle();          
        bigxtstyle.bigText(text);               
        bigxtstyle.setBigContentTitle(title);


        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setStyle(bigxtstyle)
            .setSmallIcon(icon)
            .setAutoCancel(true)

            .setSound(alarmSound)
            .setDeleteIntent(pendingIntent)                     
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));     


        Notification noti = mBuilder.build();


        mNotificationManager.notify(notificationid++, noti);

This code works, and displays the text as advertised with word wrapping. 此代码有效,并显示通过自动换行宣传的文本。 However, when a subsequent notification happens the previous notification loses its text. 但是,当后续通知发生时,先前的通知会丢失其文本。 Can anyone help resolve this issue? 有人可以帮忙解决这个问题吗? It could be something I'm setting incorrectly, I am new to the android apis. 它可能是我设置不正确的东西,我是android apis的新手。

Android only displays one expanded notification by default. Android默认情况下仅显示一个展开的通知。 Your notification doesn't lose its content, it just gets compressed and only shows the normal one-line content. 您的通知不会丢失其内容,只会被压缩并仅显示正常的单行内容。 But it seems that you don't specify this, therefore the compressed notification is empty. 但似乎您没有指定此内容,因此压缩通知为空。

You may use setContentTitle() and setContentText() to set the one-line texts. 您可以使用setContentTitle()setContentText()来设置单行文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM