Set a Custom Notification Icon (Android)

In order to use Androids custom notification icon functionality, a new method can be used when creating the PushConnector instance, e.g.


mPushConnector = new PushConnector.Builder("XTREME_PUSH_APP_KEY", "GOOGLE_PROJECT_NUMBER")
            .setIcon("iconfilenamewithoutextension") .create(this); 

This will set the icon for the notifications with an image from the res/drawablefolder of the app. In this example, the library will try to look for a file called iconfilenamewithoutextension.jpg or iconfilenamewithoutextension.png etc. in the res/drawable folder. If the file cannot be found, the default app icon will be used instead. 

If you do set an icon, the library will also search for a color entry with the same name in one of the XML files in the res/values to use as a background colour behind the icon. This entry could look like the following: 

<!-- color int as #AARRGGBB (alpha, red, green, blue) -->
<color name="iconfilenamewithoutextension">#ff2266ff</color>

This additional functionality caters for the notification icon scheme introduced in Lollipop, where the icons should be white only and have transparent sections for a background colour to show through (see https://developer.android.com/design/patterns/notifications.html#use_distinct_icons)

Have more questions? Submit a request

0 Comments

Article is closed for comments.