簡體   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);

此代碼有效,並顯示通過自動換行宣傳的文本。 但是,當后續通知發生時,先前的通知會丟失其文本。 有人可以幫忙解決這個問題嗎? 它可能是我設置不正確的東西,我是android apis的新手。

Android默認情況下僅顯示一個展開的通知。 您的通知不會丟失其內容,只會被壓縮並僅顯示正常的單行內容。 但似乎您沒有指定此內容,因此壓縮通知為空。

您可以使用setContentTitle()setContentText()來設置單行文本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM