微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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,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,new Intent(),0));     


        Notification noti = mBuilder.build();


        mnotificationmanager.notify(notificationid++,noti);

代码有效,并显示通过自动换行宣传的文本.但是,当后续通知发生时,先前的通知会丢失其文本.有人可以帮忙解决这个问题吗?这可能是我设置错误的东西,我是android apis的新手.

解决方法

Android认情况下仅显示一个展开的通知.您的通知不会丢失内容,只会被压缩并仅显示正常的单行内容.但似乎您没有指定此内容,因此压缩通知为空.

您可以使用setContentTitle()setContentText()设置单行文本.

原文地址:https://www.jb51.cc/android/315199.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐