question

Michal Töpfer avatar image
Michal Töpfer asked

Android Notification Icon

I have implemented push notifications using your Unity plugin. I want to ask how to create custom notification icon.

I've read on https://api.playfab.com/docs/push-for-android that I should post JSON with the icon name, which I have in my Android\res\drawable folder. Should it be in "Assets/Plugins/Android/res/drawable" ? And should I write the icon name with file extension ("icon.jpg")?

I have a "icon.jpg" file in "Assets/Plugins/Android/res/drawable" folder. I tried sending two notifications. First with "Icon": "icon" - this one showed up without a custom icon (with a white square in gray circle). The second had "Icon": "icon.jpg" - this one caused the app to stop working with the following error:

Unable to start receiver com.playfab.unityplugin.GCM.NotificationPublisher: java.lang.IllegalArgumentException: Invalid notification (no valid small icon)...
...
at com.playfab.unityplugin.GCM.PlayFabNotificationSender.sendNotificationById(PlayFabNotificationSender.java:73)
at com.playfab.unityplugin.GCM.NotificationPublisher.onReceive(NotificationPublisher.java:27)
...
Push 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.

1807605288 avatar image
1807605288 answered

Push Notifications have gone through so many changes, that once again, the previous accepted answer isn't the right one anymore.

We've updated to FCM.

Delete the old PlayFab custom push plugin, install FCM, update your references to our old plugin to use FCM, using the FCM documentation.

Our guides have had a rough pass to describe this, but I don't think they're correct on every detail yet, so the short answer is this:

  1. Install the google-services.json file from the Firebase Console
  2. Install the FCM unity plugin
  3. Set up your code using the FCM documentation (linked above)
  4. Send a test push message from the FIREBASE CONSOLE (not PlayFab)
  5. If you experience any problems before this step, you should contact FCM support, as PlayFab isn't involved yet
  6. Once you have a working test push from the Firebase Console, retrieve the push-token from FCM via the callback, log into PlayFab, and register for push with PlayFab (You should re-register on every PlayFab login).
  7. Push from PlayFab to device should work
10 |1200

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

brendan avatar image
brendan answered

Specifically in Unity, the "Icon" parameter value should be the resource name for the icon (the Identifier). That will cause the plugin to automatically substitute the correct filename, using the file from your resources. I've filed a bug to get that doc updated to clarify this.

7 comments
10 |1200

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

Michal Töpfer avatar image Michal Töpfer commented ·

Does the identifier mean filename? If so, I have tried it (my first attempt in the question) and got white square.

Could you please provide an example?

0 Likes 0 ·
brendan avatar image brendan Michal Töpfer commented ·

No it is the identifier you would use with a call to Unity's getIdentifier() method, so get the resource.

0 Likes 0 ·
Michal Töpfer avatar image Michal Töpfer brendan commented ·

I still can't work it out. I have tried putting specific version of my file (ic_icon.png) to all the res/drawable-hdpi (and xhdpi, mdpi, ...) and I am still getting the square. When I try to send a notification with a different icon parameter, the app crashes (I suppose that is default behaviour), but with the "Icon":"ic_icon", the app does not crash, but the icon is only a gray circle with white square.

My goal is to olny get the notification icon to be same as the icon of my game. I think it would be best if this was the default behaviour of the plugin.

0 Likes 0 ·
Show more comments
robert avatar image robert commented ·

We have the same issue here. No icon displayed at all. (Tried without Icon parameter and with Icon parameter set and icon resources included). Any news on this?

0 Likes 0 ·
robert avatar image robert robert commented ·

Any news on this?

0 Likes 0 ·
marcowilliamspf avatar image
marcowilliamspf answered

So I deleted my previous comment on here because it was just out-right wrong! I've figured this out and the only fix is a two part one.

1> Your icon needs to be white & transparent only. Anything else won't render correctly on Android 7.0+

2> I've made some code changes to support Android 7.0+ , actually Lollipop +

 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);


With this new release (which should go out in the next day or so, Monday at the latest) you have two files in your drawable folder "app_icon.png" & "app_icon_transparent.png".

I also found this AMAZING site: https://romannurik.github.io/AndroidAssetStudio/index.html that will create your entire drawable for notification icons based on a single image you upload. (kudos Roman for creating such an awesome resource).

Thanks!

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.

robert avatar image robert commented ·

This sounds great! Will give it a try as soon as it is available.

On a side note, if you are going to build a new version anyway, you think you can get rid of these two debug messages:

PlayFabPluginEventHandler.cs:
Debug.LogFormat("Createding new _PLayFabGO");

and

PlayFabAndroid.cs:

Debug.LogFormat("SenderID: {0}", SenderID);

Thanks!

0 Likes 0 ·
robert avatar image
robert answered

The new android push plugin requires PlayFabAdInfo.aar which now requires minSDKVersion = 16 (jelly bean). Is this on purpose?

9 comments
10 |1200

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

brendan avatar image brendan commented ·

That's correct - older versions of their OS don't have good support for this, so we had to make the requirement Jelly Bean and up.

0 Likes 0 ·
robert avatar image robert commented ·

damn, so no notifications for us, would lose too much potential android users then. thanks for the information

0 Likes 0 ·
brendan avatar image brendan robert commented ·

Bear in mind that you can still use simple notifications without the plugin.

0 Likes 0 ·
robert avatar image robert brendan commented ·

On a side note, I really would suggest trying to get at least API level 15 compatibility. This android push notification plugin is the only plugin i'm aware of requiring version 16. (we use a ton of android plugins actually). At least it should compile and link and just disable itself when running on devices with API lower than 16.

1 Like 1 ·
Show more comments
Show more comments
fiveampsoftware avatar image
fiveampsoftware answered

It looks like we run into the same issue and can't update our api level - we are currently at 15 and can't update to 16. If we were to not use the plugin how would we do that with AndroidDevicePushNotificationRegistration? We would still need a token from GCM

If we're not using any advanced push notification functions, would it be okay to manually change the api level from the plugin?

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.

marcowilliamspf avatar image marcowilliamspf commented ·

yes you should be able to download the plugin source and set it up to build to a lower API Level. There is a gradle script that you can find in the sidebar with a method called "ExportJars" this will put your .AAR in the release folder

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.