2016-05-16 12 views
2

Ich versuche, ein Bild in der Benachrichtigungsleiste anzuzeigen. Aber wenn ich Bild, das JPG-Format ist Meine Anwendung geschlossen mit Android gestoppt Prozess. Und wenn ich ein PNG-Symbol einstelle, wird das Symbol dort nicht angezeigt. Ich ändere die Größe meines Symbols 32dp und versuche auch 24dp. Heres mein Code und Screenshot -Android-Benachrichtigung zeigt Titelbild JPG- oder PNG-Format nicht an

public void shownotification(View view){ 

    Intent intent = new Intent(); 
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0); 
    Notification notification = new Notification.Builder(MainActivity.this) 
      .setTicker("Tittle") 
      .setContentTitle("Content Tittle") 
      .setContentText("All details of Content") 
      .setSmallIcon(R.drawable.cdc) 
      .setContentIntent(pendingIntent).getNotification(); 
    notification.flags = Notification.FLAG_AUTO_CANCEL; 
    NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
    notificationManager.notify(0,notification); 
} 

enter image description here

+0

Welche Android-Version hast du benutzt? – USKMobility

+0

API 22, Lollipop Version. – Istiyak

+0

@Istiyak hast du irgendeine Lösung bekommen? – Pallavi

Antwort

0

Ursache für das Problem ist für Lollipop 5.0 und höher Version "Benachrichtigungssymbole müssen vollständig weiß sein".

Bitte beachten Sie folgende Ihr Benachrichtigungssymbol https://design.google.com/icons/

zu erstellen und den Code ändern Symbol mit folgendem Code

public void shownotification(View view){  
      Intent intent = new Intent(); 
      PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0); 
      Notification notification = new Notification.Builder(MainActivity.this) 
        .setTicker("Tittle") 
        .setContentTitle("Content Tittle") 
        .setContentText("All details of Content")    
        .setContentIntent(pendingIntent).getNotification(); 
     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ 
      notification.setSmallIcon(R.drawable.cdc_icon_transperent); 
     } else { 
      notification.setSmallIcon(R.drawable.cdc); 
     } 

      notification.flags = Notification.FLAG_AUTO_CANCEL; 
      NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
      notificationManager.notify(0,notification); 
} 

wo R.drawable.cdc_icon_transperent ist das neue Weiß-Symbol setzen

Verwandte Themen