This is a migrated thread and some comments may be shown as answers.

Android (costum) notification Icon

7 Answers 332 Views
Push Notifications
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Max
Top achievements
Rank 1
Max asked on 14 Feb 2015, 06:33 PM
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 ...

7 Answers, 1 is accepted

Sort by
0
Max
Top achievements
Rank 1
answered on 14 Feb 2015, 08:05 PM
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



0
Accepted
Anton Dobrev
Telerik team
answered on 17 Feb 2015, 04:59 PM
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.
 
0
Max
Top achievements
Rank 1
answered on 19 Feb 2015, 05:19 PM
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 :)
0
Anton Dobrev
Telerik team
answered on 23 Feb 2015, 01:58 PM
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.
 
0
venilla
Top achievements
Rank 1
answered on 21 Nov 2015, 07:08 AM

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

0
Anton Dobrev
Telerik team
answered on 24 Nov 2015, 11:49 AM
@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.
 
0
Yallalinga
Top achievements
Rank 1
answered on 28 Nov 2017, 11:52 AM

Hi,

I am updating notification bar icon when network goes down.
It is updating only where you drag the notifications on device screen.
But it is not showing at above notification bar.
How to fix this issue please help me. This is happening for SONIM XP8800 device only.

Tags
Push Notifications
Asked by
Max
Top achievements
Rank 1
Answers by
Max
Top achievements
Rank 1
Anton Dobrev
Telerik team
venilla
Top achievements
Rank 1
Yallalinga
Top achievements
Rank 1
Share this question
or