【问题标题】:NotificationCompat.BigTextStyle Content disappears on new notificationNotificationCompat.BigTextStyle 内容在新通知中消失
【发布时间】:2013-04-28 19:12:22
【问题描述】:
    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);

此代码有效,并使用自动换行显示广告中的文本。但是,当发生后续通知时,前一个通知会丢失其文本。任何人都可以帮助解决这个问题吗?可能是我设置不正确,我是android api的新手。

【问题讨论】:

    标签: android android-notifications


    【解决方案1】:

    Android 默认只显示一个展开的通知。您的通知不会丢失其内容,它只是被压缩并且只显示正常的单行内容。但是好像你没有指定这个,所以压缩后的通知是空的。

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

    【讨论】:

    • 有没有办法抑制这种行为并始终显示展开的内容?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多