2013-04-28 15 views
7
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); 

Ten kod działa i wyświetla tekst jako anonsowany z zawijaniem słów. Jednakże, gdy pojawi się kolejne powiadomienie, poprzednie powiadomienie traci swój tekst. Czy ktoś może pomóc w rozwiązaniu tego problemu? To może być coś, co ustawiam niepoprawnie, jestem nowy w apisach Androida.NotificationCompat.BigTextStyle Treść znika po nowym powiadomieniu

Odpowiedz

11

System Android wyświetla domyślnie tylko jedno rozszerzone powiadomienie. Twoje powiadomienie nie traci zawartości, jest po prostu kompresowane i pokazuje tylko normalną zawartość jednej linii. Wydaje się jednak, że tego nie określasz, dlatego skompresowane powiadomienie jest puste.

Możesz użyć setContentTitle() i setContentText(), aby ustawić tekst jednolinijowy.

+0

Czy mimo to można ukryć to zachowanie i zawsze wyświetlać rozszerzoną zawartość? – Watson

+0

Nie, nie sądzę – Floern

Powiązane problemy