15

When using Parse for push notifications our app always displayed the application's launcher icon. In the latest Android 5.1 version, the icon appears to be blank (a white square).

I tried setting the icon in the meta data:

<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/noti_icon"/>

Based on the question here

But nothing seems to work. Any ideas?

Community
  • 1
  • 1
Shahal Hazan
  • 371
  • 1
  • 3
  • 7

4 Answers4

12

You must use a transparent and white icon under Android Lollipop 5.0 or greater. You can extend ParsePushBroadcastReceiver class and override the two methods to get your notification icon compatible with these Android APIs.

    @Override
protected int getSmallIconId(Context context, Intent intent) {
    return R.drawable.your_notifiation_icon;
}

@Override
protected Bitmap getLargeIcon(Context context, Intent intent) {
    return BitmapFactory.decodeResource(context.getResources(), R.drawable.your_notifiation_icon);
}

Remember to customize your code to support Lollipop and previous APIs.

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        return BitmapFactory.decodeResource(context.getResources(), R.drawable.your_notifiation_icon_lollipop);
    }
    else{
        return BitmapFactory.decodeResource(context.getResources(), R.drawable.your_notifiation_icon);
    }
Pelanes
  • 3,451
  • 1
  • 34
  • 32
  • I implemented the getSmallIconId and it worked as you exaplained – Shahal Hazan Apr 29 '15 at 19:26
  • 1
    Many thanks for your answer @Pelanes. So to extend it, basically you have to create a class like MyPushBroadcastReceiver extending ParsePushBroadcastReceiver and overriding getSmallIconId(...) and getLargeIcon(...). Not forget to specify your receiver in manifest. On lollipop both small and big icons will be used. On emulator 2.3.7 (which I tested) only small. – Vito Valov Jul 05 '15 at 01:54
2

It is not related to Parse or push nitification, but just how Android 5.0 handles notification icons. See this releated question for details: Notification bar icon turns white in Android 5 Lollipop

Community
  • 1
  • 1
Muzikant
  • 8,070
  • 5
  • 54
  • 88
0

Although @Pelanes has the correct answer (and should be accepted), here's what I did. Note that the Parse docs for getSmallIconId state the following:

Retrieves the small icon to be used in a Notification. The default implementation uses the icon specified by com.parse.push.notification_icon meta-data in your AndroidManifest.xml with a fallback to the launcher icon for this package. To conform to Android style guides, it is highly recommended that developers specify an explicit push icon.

So it is not entirely necessary to override the getSmallIconId() and getLargeIcon() methods.

What I did to solve the problem was I just made a copy of my icon, punched transparent "holes" into the icon, and set the com.parse.push.notification_icon meta-data in my manifest to point to this new icon.

For Android 5.0, it is required for your notification icon to be white and transparent, as others have mentioned. So creating the separate icon is necessary. One line in the manifest and one new drawable file is all it takes.

h_k
  • 1,674
  • 1
  • 24
  • 46
  • Are you sure that we don't need to define how different OS versions should handle the notification icon? I performed what you suggested and it seems that the notification icon set with `com.parse.push.notification_icon` is now used in both Android 4.4 and 5.1. – Alex Aug 16 '15 at 17:36
  • I tested with 5.1 and 4.4.2. 5.1 uses the new icon, 4.4.2 uses to normal app icon... Not sure why that is happening for me but not for you. Maybe to play it safe you'll need to differentiate though. I'll edit my answer. – h_k Aug 17 '15 at 16:56
0

Try this code.

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(largeIcon)
                .setContentText(data)
                .setContentTitle("Notification from Parse")
                .setContentIntent(pendingIntent);
Jignesh Goyani
  • 1,020
  • 9
  • 17