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

Mã này hoạt động và hiển thị văn bản như được quảng cáo bằng gói từ. Tuy nhiên, khi thông báo tiếp theo xảy ra, thông báo trước đó sẽ mất văn bản. Bất cứ ai có thể giúp giải quyết vấn đề này? Nó có thể là một cái gì đó tôi đang thiết lập không chính xác, tôi mới vào apis android.NotificationCompat.BigTextStyle Nội dung biến mất trên thông báo mới

Trả lời

11

Android chỉ hiển thị một thông báo mở rộng theo mặc định. Thông báo của bạn không bị mất nội dung, thông báo sẽ bị nén và chỉ hiển thị nội dung một dòng thông thường. Nhưng có vẻ như bạn không chỉ định điều này, do đó thông báo nén bị trống.

Bạn có thể sử dụng setContentTitle()setContentText() để đặt văn bản một dòng.

+0

Có cách nào để ngăn chặn hành vi này và luôn hiển thị nội dung mở rộng không? – Watson

+0

Không, tôi không nghĩ vậy – Floern

Các vấn đề liên quan