2017-06-19 71 views
4

我在我的android應用程序中顯示多個通知。在摺疊模式下顯示多個通知第二個通知Android

當有單個通知它顯示正確。

enter image description here

但是,當我產生第二通知,默認情況下崩潰顯示第二個通知。

enter image description here

如果我手動展開第二個通知則顯示爲:

enter image description here

我想用默認值顯示在擴展模式下的通知。

這裏是我的代碼:

int num = (int) System.currentTimeMillis(); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, num /* Request code */, intent, 
       PendingIntent.FLAG_ONE_SHOT); 


     NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); 
     bigTextStyle.setBigContentTitle(title); 
     bigTextStyle.bigText(messageBody); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.corco) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setStyle(bigTextStyle) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(num /* ID of notification */, notificationBuilder.build()); 

我這麼想嗎?或做錯了什麼?

在此先感謝。

回答

0

我解決了它。我沒有爲摺疊通知設置任何ContentTitle和ContentText。

這是我更新的代碼:

int num = (int) System.currentTimeMillis(); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, num /* Request code */, intent, 
       PendingIntent.FLAG_ONE_SHOT); 


     NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); 
     bigTextStyle.setBigContentTitle(title); 
     bigTextStyle.bigText(messageBody); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.corco) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setStyle(bigTextStyle) 
       .setContentTitle(title) 
       .setContentText(messageBody) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(num /* ID of notification */, notificationBuilder.build());