Search code examples
androidbroadcastreceivermixpanel

Customising Notification icon for Android, using Mixpanel


Using Mixpanel I am able to send out notifications directly from their control panel, however currently it uses a weirdly cropped version of the launcher icon as the notification icon.

I have seen some answers for customising the icon using a customised BroadcastReceiver, but I can't seem to get it to working in this case. Has anyone successfully managed to change the notification icon when sending directly from Mixpanel?

Thanks.


Solution

  • Actually, there is a way to set a custom icon for android push notifications without writing your own custom broadcast receiver. Recent versions of the Mixpanel android library understand a "mp_icnm" parameter that can refer to the name of a resource in your application. The library itself is also packaged with a set of predefined icons you can use. The quick way is to put the following snippet into the "custom data" field

    {"mp_icnm":"com_mixpanel_android_ic_megaphone"}
    

    I've attached a screenshot of the Mixpanel app with a picture of the text field. You'll want to be sure that this data is entered in "Android" preview mode when you enter your data, as shown in the illustration.

    Illustration of custom data field in Mixpanel push notification composer screen, showing the appropriate spot for the JSON above

    You can use any drawable resource in your app for an icon- the whole list of prepackaged notification icons can be found here in the Mixpanel library, and their resource names are listed below.

    • com_mixpanel_android_ic_bell
    • com_mixpanel_android_ic_clipboard_checkmark
    • com_mixpanel_android_ic_coin
    • com_mixpanel_android_ic_flag
    • com_mixpanel_android_ic_gear
    • com_mixpanel_android_ic_inbox
    • com_mixpanel_android_ic_megaphone
    • com_mixpanel_android_ic_phone
    • com_mixpanel_android_ic_rocket
    • com_mixpanel_android_ic_sale_tag
    • com_mixpanel_android_ic_sync
    • com_mixpanel_android_ic_trophy
    • com_mixpanel_android_ic_vip
    • com_mixpanel_android_ic_warning

    Be aware that the Mixpanel resources might be removed by your proguard configuration, so you'll want to be sure that you haven't stripped them if you want to use them.