2016-05-16 8 views
2

通知バーに画像を表示しようとしています。しかし、私はJPG形式の画像を設定する私のアプリケーションはアンドロイドがプロセスを停止して閉じた。そして、PNGアイコンを設定するとアイコンが表示されません。私は両方のタイプのアイコンのサイズを32dpに変更し、24dpのサイズも試します。 HERESに私のコードとスクリーンショット - 問題の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、Lollipopバージョン。 – Istiyak

+0

@Istiyakあなたは解決策を得ましたか? – Pallavi

答えて

0

原因は、「通知アイコンは完全に白でなければならない」5.0ロリポップのためにとバージョン の上にあります。

あなたの通知アイコンhttps://design.google.com/icons/

を作成し、コードの下

R.drawable.cdc_icon_transperentが新しい白のアイコン

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

にアイコンを設定するようにコードを変更するには、次をご参照ください

関連する問題