Istiyak
Istiyak

Reputation: 723

Android Notification does not show Title Image JPG or PNG format

I am trying show an image in Notification Bar . But when i set image which is JPG format My application closed with android stopped process. And when i set a PNG icon, icon does not show there. I resize my both type of icon 32dp and try also 24dp size. Heres my code and screenshot --

  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

Upvotes: 4

Views: 1405

Answers (1)

Pallavi
Pallavi

Reputation: 674

Cause for the issue is for 5.0 Lollipop and above version "Notification icons must be entirely white".

Please refer following to create your notification icon https://design.google.com/icons/

and change the your code to set icon with below 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);
}

where R.drawable.cdc_icon_transperent is the new white icon

Upvotes: 2

Related Questions