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

このコードは機能し、ワープされた広告テキストを表示します。ただし、後続の通知が発生すると、前の通知でテキストが失われます。誰でもこの問題の解決に役立つことができますか?それは私が間違って設定しているものかもしれない、私はアンドロイドのapiに新しいです。NotificationCompat.BigTextStyleの内容は新しい通知で消えます

答えて

11

Androidでは、デフォルトで1つの拡張通知のみが表示されます。あなたの通知はコンテンツを失うことなく、ただ圧縮され、通常の1行のコンテンツのみを表示します。しかし、あなたがこれを指定していないと思われるので、圧縮された通知は空です。

setContentTitle()setContentText()を使用して、1行のテキストを設定することができます。

+0

この動作を抑制し、常に拡張コンテンツを表示する方法はありますか? – Watson

+0

いいえ、私はそうは思わない – Floern

関連する問題