简体   繁体   中英

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 only displays one expanded notification by default. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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