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

前端之家收集整理的这篇文章主要介绍了android – NotificationCompat.BigTextStyle内容在新通知上消失前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. String ns = Context.NOTIFICATION_SERVICE;
  2. NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns);
  3. int icon = R.drawable.ic_launcher;
  4. CharSequence tickerText = title;
  5. long when = System.currentTimeMillis();
  6.  
  7.  
  8. Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  9. if(alarmSound == null){
  10. alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
  11. if(alarmSound == null){
  12. alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  13. }
  14. }
  15.  
  16. Intent intent = new Intent();
  17. PendingIntent pendingIntent
  18. = PendingIntent.getActivity(this,intent,0);
  19.  
  20. NotificationCompat.BigTextStyle bigxtstyle =
  21. new NotificationCompat.BigTextStyle();
  22. bigxtstyle.bigText(text);
  23. bigxtstyle.setBigContentTitle(title);
  24.  
  25.  
  26. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
  27. .setStyle(bigxtstyle)
  28. .setSmallIcon(icon)
  29. .setAutoCancel(true)
  30.  
  31. .setSound(alarmSound)
  32. .setDeleteIntent(pendingIntent)
  33. .setContentIntent(PendingIntent.getActivity(this,new Intent(),0));
  34.  
  35.  
  36. Notification noti = mBuilder.build();
  37.  
  38.  
  39. mNotificationManager.notify(notificationid++,noti);

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

解决方法

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

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

猜你在找的Android相关文章