8
    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的新手。

4

1 回答 1

11

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

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

于 2013-04-28T20:12:38.873 回答