2016-05-16 89 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是新的白色图标