GCM notification icon overlapping (two times the same icon, small and huge)

722 views Asked by At

I am using GCM in my app, the notification icon seems to be OK in android 4.1 and 4.4 devices, but in android 5.1 i can see two icons one very very small and one with normal size. The small is in the lower right corner overlapping the huge icon. You can see it in this picture:

enter image description here

This is my code:

private void generateNotification(String message) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(Constants.COMING_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        String appName = getResources().getString(R.string.app_name);       

        int width;
        int height;
        if (Util.checkAndroidVersionUpperOrEqualThan(11)){      
            width = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width); 
            height = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        }else{
            width = 64;
            height = 64;
        }

        image = Bitmap.createScaledBitmap(image, width, height, false);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setLargeIcon(image)
        .setContentTitle(appName)
        .setContentText(message)
        .setSound(defaultSoundUri)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setContentIntent(pendingIntent)
        .setAutoCancel(true)
        .setCategory(NotificationCompat.CATEGORY_MESSAGE)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message));

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0,notificationBuilder.build());
    }
1

There are 1 answers

1
AniV On

The android documentation for Notification class about the setSmallIcon() states that:

Set the small icon resource, which will be used to represent the notification in the status bar. The platform template for the expanded view will draw this icon in the left, unless a large icon has also been specified, in which case the small icon will be moved to the right-hand side.

This mean the Large icon is somehow ignored by the API. Try removing the code where you are checking the version. Not sure why that would cause this.