Support Topics Documentation Slack YouTube Blog

Customizing Android notifications from API without template


(Milen Marinov) #1

I mentioned that in another thread but since it’s a separate topic I’m posting it here:

I don’t use a template because I need to customize the notification from code and as far as I know you cannot customize templates.
The two specific things I need are:

  1. Deliver notification to particular devices that are determined dynamically in code
  2. Add custom header information that is also dynamic

(I know about Smart Text but it doesn’t achieve the job in this case as the info is not directly related to the user, receiving the notification)

So, another functionality that I’m lacking is being able to specify small/big icon for an Android notification.
If I use a template I cannot set the above two things. And if I create a notification from code I cannot specify notification icons. Is there a workaround about this? If not - do you intend to implement such functionality?

Thanks,
Milen Marinov


(Anton Govorushkin) #2

By saying this

If I use a template I cannot set the above two things.

you mean that you are getting some kind of an error when receiving a notification/notification not showing up/you can’t or don’t want to use templates?
Asking because there is an option to specify icons - https://monosnap.com/file/rNKIJWZKq2Mw1D7pUa7d1MgU2ZshGJ

Anton


(Milen Marinov) #3

Hi Anton,

Yes, with templates you can specify icons. The problem is that when you use templates from code (at least through the SDK) you cannot modify them. And I need to modify it every time a notification is sent with dynamic information that is not know when I compose the template in the console. To be more clear here is an excerpt from my code:

                // Creates delivery options
                DeliveryOptions deliveryOptions = new DeliveryOptions();
                deliveryOptions.setPushSinglecast(notifiedDevices);

                // Creates publish options
                PublishOptions publishOptions = new PublishOptions();
                publishOptions.putHeader("android-ticker-text", tickerText);
                publishOptions.putHeader("android-content-text", message);
                publishOptions.putHeader("ios-alert", message);
                publishOptions.putHeader("ios-badge", "1");
                publishOptions.putHeader("signalId", signalId);
                publishOptions.putHeader("ios-category", "kNotificationCategoryNewSignal");

notifiedDevices, message and signalId are the dynamic things that I need to set in the notification.

Hope this helps you understand the use case!

Best,
Milen


(Vladimir Yalovy) #4

Hi @milen-marinov

Add custom header information that is also dynamic. The info is not directly related to the user, receiving the notification.

Will this information be the same for all recipients?


(Milen Marinov) #5

Hi Vladimir,

Yes, all interested users receive the same notification.


(Vladimir Yalovy) #6

You want something similar to this:

  {
    MessageStatus statusFirstPublishNotification = publishNotification( notifiedDevices, message, iosBadge, tickerText, signalId );

    MessageStatus statusSecondPublishNotification = publishNotification( notifiedDevicesAnother, messageAnother, iosBadgeAnother, tickerTextAnother, signalIdAnother );
  }

  private MessageStatus publishNotification( List<String> notifiedDevices, String message, String iosBadge, String tickerText, String signalId )
  {
    // Creates delivery options
    DeliveryOptions deliveryOptions = new DeliveryOptions();
    deliveryOptions.setPushSinglecast( notifiedDevices );

    // Creates publish options
    PublishOptions publishOptions = new PublishOptions();
    publishOptions.putHeader( "android-ticker-text", tickerText );
    publishOptions.putHeader( "android-content-text", message );
    publishOptions.putHeader( "ios-alert", message );
    publishOptions.putHeader( "ios-badge", iosBadge );
    publishOptions.putHeader( "signalId", signalId );
    publishOptions.putHeader( "ios-category", "kNotificationCategoryNewSignal" );

    return Backendless.Messaging.publish( message, publishOptions, deliveryOptions );
  }

?


(Milen Marinov) #7

I don’t understand what problem does this example solve!?


(Vladimir Yalovy) #8

Your question: Is there an analogue for android publishOptions header to specify small/big icon for an Android notification like an iOS (PublishOptions.IOS_BADGE_TAG = “ios-badge”) if you publish notification from code?


(Milen Marinov) #9

Yes, I want to be able to specify Android notification icons when sending the notification from code (without a template).


(Vladimir Yalovy) #10

While this is not possible. While the plans were not to add this functionality. I will discuss the possibility of adding such functionality.


(Milen Marinov) #11

Thanks a lot!
An alternative solution would be to allow editing of templates - e.g. you have a saved template with specified icons and you can modify it’s message, ticker, custom headers, etc. from code.


(Mark Piller) #12

Since we already support icons as a part of templates, I think a better approach would be to enhance the templates behavior to accommodate your use case (i.e. being able to modify parts of template both from the content and the visual perspective).