2016-05-16 208 views
2

我試圖在通知欄中顯示圖像。但是,當我設置JPG格式的圖像我的應用程序關閉與Android停止進程。當我設置一個PNG圖標時,圖標不顯示在那裏。我調整我的兩種圖標類型32dp,並嘗試24dp大小。繼承人我的代碼和截圖 -Android通知不顯示標題圖像JPG或PNG格式

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

你用什麼android版本? – USKMobility

+0

API 22,棒棒糖版本。 – Istiyak

+0

@Istiyak你有沒有得到任何解決方案? – Pallavi

回答

0

原因的問題是5.0棒棒糖及以上版本 「通知圖標必須是全白」。

請參考以下內容來創建您的通知圖標https://design.google.com/icons/

,改變你的代碼來設置圖標,下面的代碼

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); 
} 

其中R.drawable.cdc_icon_transperent是新的白色圖標