Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 5.1 push notification icon is blank

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?

like image 645
Shahal Hazan Avatar asked Apr 19 '15 10:04

Shahal Hazan


2 Answers

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);
    }
like image 100
Pelanes Avatar answered Sep 28 '22 08:09

Pelanes


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

like image 28
Muzikant Avatar answered Sep 28 '22 07:09

Muzikant