<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: David Brown</title>
    <description>The latest articles on Forem by David Brown (@davebrown1975).</description>
    <link>https://forem.com/davebrown1975</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F198946%2Fd475a0f4-201e-48d3-ac6d-d5a7b6272af1.jpeg</url>
      <title>Forem: David Brown</title>
      <link>https://forem.com/davebrown1975</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/davebrown1975"/>
    <language>en</language>
    <item>
      <title>Localised notifications with Firebase cloud messaging (FCM)</title>
      <dc:creator>David Brown</dc:creator>
      <pubDate>Wed, 09 Nov 2022 09:08:05 +0000</pubDate>
      <link>https://forem.com/davebrown1975/localised-notifications-with-firebase-cloud-messaging-fcm-ecn</link>
      <guid>https://forem.com/davebrown1975/localised-notifications-with-firebase-cloud-messaging-fcm-ecn</guid>
      <description>&lt;p&gt;If you need to send localised push notifications from a Java server side application to mobile devices with Firebase Cloud Messaging (FCM), whether your server side is Grails, Spring boot or any other Java based framework utilising the Firebase (Admin) SDK then search no more as it's not so clear in the official documentation.  Most examples focus on the REST or JS implementations.&lt;/p&gt;

&lt;p&gt;In my use case, I wanted to alert users subscribing to a specific Topic of a particular event.  Users of this app are distributed globally so it was important to localise the messages depending on the users locale according to their device.  From the server side, I just want to generate the notification and let Firebase's servers handle the notifications to each device subscribed to the topic and then the device it self display a locales message, both the title and subtitle,  on both Android and IOS devices. &lt;/p&gt;

&lt;p&gt;Fortunately Firebase lets us do this by specifying localised 'keys', instead of specifying the title and body.    However finding an example was more of a struggle as the documentation is somewhat lacking.&lt;/p&gt;

&lt;p&gt;What we have to do is establish Options objects for each platform, i.e. one for Android and one for Apple devices and then deep within nested Builders we can finally set the localised keys.  These then can be interpreted from the resources within the mobile App itself and will be displayed to the user, both when the app is in the foreground AND also when it's in the background.&lt;/p&gt;

&lt;p&gt;So without further ado,  let's look at the code:  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: I'm omitting the rest of the app code assuming you already know how to setup Firebase etc and just need to see how to generate the notification.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void sendLocalisedNotification(String topic, String titleKey, String bodyKey) {
        // Set localisation key for Android
        AndroidConfig androidConfig = AndroidConfig.builder()
            .setNotification(
                AndroidNotification.builder()
                    .setTitleLocalizationKey(titleKey)
                    .setBodyLocalizationKey(bodyKey)
                    .build()
            ).build()

        // Set localisation key for Apple devices
        ApnsConfig apnsConfig = ApnsConfig.builder()
            .setAps(Aps.builder()
                .setAlert(ApsAlert.builder()
                    .setTitleLocalizationKey(titleKey)
                    .setSubtitleLocalizationKey(bodyKey)
                    .build()
                ).build()
            ).build()

        Message message = Message.builder()
            .setTopic(topic)
            .setAndroidConfig(androidConfig)
            .setApnsConfig(apnsConfig)
            .build();

        // And then send the message to the devices subscribed to the provided topic.
        try {
            String response = FirebaseMessaging.getInstance().send(message);

            // Response is a message ID string.
            log.debug("Firebase message $topic sent: " + response);
        } catch (Exception ex) {
            log.warn("Firebase message $topic failed: " + ex.message);
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that's the gist of it, this method can be called with the topic we want to publish to, the title key and the body key.&lt;/p&gt;

&lt;p&gt;I hope this helps save someone time discovering how to accomplish localised messages under a Java environment using the FCM SDK.  &lt;/p&gt;

&lt;p&gt;Dave / &lt;a href="https://tucanoo.com"&gt;Tucanoo Solutions&lt;/a&gt;&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>java</category>
      <category>notifications</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Super Fast Prototyping with Grails Tutorial Available</title>
      <dc:creator>David Brown</dc:creator>
      <pubDate>Wed, 12 Feb 2020 08:39:54 +0000</pubDate>
      <link>https://forem.com/davebrown1975/super-fast-prototyping-with-grails-tutorial-available-1aij</link>
      <guid>https://forem.com/davebrown1975/super-fast-prototyping-with-grails-tutorial-available-1aij</guid>
      <description>&lt;p&gt;One of the greatest benefits of the Grails framework is how it allows you to put together a Proof Of Concept(POC) or a web app prototype in such a short period time.&lt;/p&gt;

&lt;p&gt;In a current world where there is lots of focus on UI frameworks and microservice architectures, sometimes, you just need to build something quickly without worrying about different front and backend layers.  &lt;/p&gt;

&lt;p&gt;Grails allows you to build apps fast, but with the benefit of sitting on top of the most robust Java-based libraries in existence, Spring, Hibernate, etc. etc.&lt;/p&gt;

&lt;p&gt;In this tutorial, you'll see how to build a simple CRM backed by a H2 in-memory database, prepopulating itself with 1000 fictitious records.&lt;/p&gt;

&lt;p&gt;The user is provided with basic CRUD screens,  create, edit, and a rich Datatables based list screen to allow filtering, sorting and ajax driven paging of the customer records.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/tucanoo/crm_grails"&gt;Download full source on github&lt;/a&gt; Download the full source on github &lt;/p&gt;

&lt;p&gt;and &lt;a href="https://www.tucanoo.com/how-to-build-a-simple-crm-with-grails-4/"&gt;Read the full tutorial&lt;/a&gt;&lt;/p&gt;

</description>
      <category>grails</category>
      <category>tutorial</category>
      <category>groovy</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
