question

Koen avatar image
Koen asked

How to implement different Android Push Notification Icons

We're using the latest package of the Unity AndroidPushPlugin (Android 7.0+ Plugin Fixes (#188)).

We've added an "app_icon.png" and an "app_icon_transparent.png" in the res/drawable folder in Unity's Android plugin folder, but it appears that only the _transparent variant is used for both icons in the notification area of Android (large and small):

On the left you can see the result in the notification area (the white L is barely visible), on the right the actual _transparent.png (except the gray background of course) (the app_icon.png is totally different and colored and is not visible in the notification area).

It is possible to use two different icons just like other Android apps do (like WhatsApp)? We'd like to use the regular app icon as the large and a white-only small one.

apissdksPush Notifications
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
marcowilliamspf avatar image
marcowilliamspf answered

Hi @kvanlin this is not going to be what you want to hear, so I apologize in advance.

Our code in the plugin sets the _transparent on the small Icon only if it is LOLLIPOP or Greater. Take note of appIcon + "_transparent" and it always looks in the drawable folders.

Large Icons are only supported on LOLLIPOP or greater so for that condition, we are setting the large Icon to the App Icon with no transparency.

so for clarity, your app_icon_transparent.png should be a 256x256 black & white w/ a transparent background. The large icon can be larger dimensions. I believe the large icon can have transparency as well.

See: https://material.io/guidelines/patterns/notifications.html as this is the guide we are basing our plugin off of which is the official style & patterns guide from Google Android.

If you feel some additional logic needs to be added to the below, please let me know.


You can always view the open source code to see what it is doing.

Unity Android Push Plugin

You can contribute to by submitting a pull request to: https://github.com/PlayFab/UnitySDK

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(intent);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder.setSmallIcon(intent.getResources().getIdentifier(appIcon + "_transparent", "drawable", intent.getPackageName()));
}else{
    notificationBuilder.setSmallIcon(intent.getResources().getIdentifier(appIcon, "drawable", intent.getPackageName()));
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Bitmap icon = BitmapFactory.decodeResource(intent.getResources(), intent.getResources().getIdentifier(appIcon, "drawable", intent.getPackageName()));
    notificationBuilder.setLargeIcon(icon);
}
notificationBuilder.setContentTitle(title)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
        .setContentText(message)
        .setSound(defaultSoundUri)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
        .setAutoCancel(true)
        .setContentIntent(pendingIntent);

Again, I know this is not the answer you were looking for, but at the very least you know what is happening under the hood in our plugin and you can hopefully make changes accordingly. Or submit a recommendation for us to review.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Koen avatar image Koen commented ·

Thanks for the answer. Good to hear it wasn't an error on our side ;)

Thanks for the insight on the source side of the plugin. Sadly, we currently we don't have the manpower and knowledge for Android native coding (regarding push notifications). If we are to investigate and fix this issue we'll definitely submit a pull request on the github.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.