Android (costum) notification Icon

7 posts, 1 answers
  1. Max
    Max avatar
    19 posts
    Member since:
    Jan 2015

    Posted 14 Feb 2015 Link to this post

    is there a possibility to define the notification icon that is used on android devices?

    especially for Android Lollipop it is necessary to comply with the notification icon guides to only use a white icon as the status bar can be in different colors.
    However, all notifications have the app icon, which of course is in color and on lollipop this icon just gets reduced to an ugly white blop (see attachment)

    http://developer.android.com/design/style/iconography.html#notification


    the solution is to especially set a smallIcon (that is only white) and just use the app icon for the LargeIcon

    http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSmallIcon(int)

    yet, I could not find any possibility to set any custom parameters for a notification on android at all ...
  2. Max
    Max avatar
    19 posts
    Member since:
    Jan 2015

    Posted 14 Feb 2015 in reply to Max Link to this post

    to clarify my last statement/sentence, i did not find any flags for setting the icon, only those parameters specified under structure:
    http://docs.telerik.com/platform/backend-services/features/push-notifications/structure#platform-specific-fields

    additionally, i just had a deeper look into the (underlying?) cordova PushPlugin, which seems to have the smallIcon flag hardcoded to the application icon: 
    https://github.com/phonegap-build/PushPlugin/blob/master/src/android/com/plugin/gcm/GCMIntentService.java



  3. Answer
    Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 17 Feb 2015 Link to this post

    Hi Max,

    You are right that Android Lollipop have some new requirements for the notifications icons. The reason you are seeing a white icon is that the icon should be entirely white - thus, the black shapes are represented by the transparency levels in the icon.

    If you like to choose your custom icon, you can change the code to the plugin to:

    1. Import:
    import android.content.res.Resources;

    2. Add the following to set the icon to a custom one:
    Resources r = getResources();
               int resourceId = r.getIdentifier("iconb", "raw", context.getPackageName());
        
       NotificationCompat.Builder mBuilder =
           new NotificationCompat.Builder(context)
               .setDefaults(defaults)
               .setSmallIcon(resourceId)
               .setWhen(System.currentTimeMillis())
               .setContentTitle(extras.getString("title"))
               .setTicker(extras.getString("title"))
               .setContentIntent(contentIntent)
               .setAutoCancel(true);

    Where iconb.png is a compatible icon in the "raw" folder under App_Resources in your AppBuilder project.

    Let me know if this helps.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  4. Max
    Max avatar
    19 posts
    Member since:
    Jan 2015

    Posted 19 Feb 2015 in reply to Anton Dobrev Link to this post

    i was afraid that this is the suggested solution.

    so in order to modify this android code I added the Telerik Push Notification Plugin that is linked in the plugins overview (https://github.com/Telerik-Verified-Plugins/PushNotification) as a custom cordova plugin.
    However, I noticed that adding the plugin adds a new entry PushPlugin in the project properties rather than only marking the Telerik Push Notifications plugin as fixed (enabled).
    In order to get my custom (modified) plugin code to work, i had to disable "Telerik Push Notifications" and only use the now called PushPlugin.
    So it seems to me that the github plugin has an incorrect name, if it is supposed to be/replace "Telerik Push Notifications".

    Yet, this still does not work.
    Resources r = getResources();
    wont compile, as getResources() method is not available.
    I changed it to:
    Resources r = context.getResources();

    and that finally works and solves the problem of not having a white small icon :)
  5. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 23 Feb 2015 Link to this post

    Hello Max,

    Glad that this is working now on your side. Let me know if further questions arise.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  6. venilla
    venilla avatar
    1 posts
    Member since:
    Nov 2015

    Posted 21 Nov 2015 in reply to Anton Dobrev Link to this post

    Hi anton,

     This solution is not working for me, I still got the white color for app_icon in the notification bar..

     can you please tell how to create compatible icon

    thanks

  7. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 24 Nov 2015 Link to this post

    @venilla

    You may want to upgrade to the latest version of the push plugin and configure a default or custom notification icons in your project as explained here. This should fix the behavior. Let me know if you have further questions. 


    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top