
## Enable integration in the Synerise platform

Before you start integrating Huawei services in your app, you must configure the integration in Synerise platform. For instructions, see ["Huawei integration"](/docs/settings/tool/huawei-integration).

## Configuration

In order to integrate Huawei Mobile Services (HMS) with Synerise, you must add `.setMesaggingServiceType(MessagingServiceType.hms)` to your `Synerise.initializer`.

We recommend passing `MessagingServiceType.hms` as an argument when you build the app for AppGallery.


<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

More information about `Synerise.initializer` is available in ["Initialization"](/developers/mobile-sdk/installation-and-configuration/flutter#initialization).

</div></div></div>


## Implementing Huawei notifications in applications

1. Add the Huawei push library as a dependency and integrate it: [https://pub.dev/packages/huawei_push](https://pub.dev/packages/huawei_push).
2. Add an `onTokenEvent` callback to receive the HMS token. In the callback, send the token to Synerise by using [`Synerise.notifications.registerForNotifications`](/developers/mobile-sdk/method-reference/flutter/campaigns#register-for-push-notifications) method:  
    
   <pre><code class="language-js">void _onTokenEvent(String event) {
       // Requested tokens can be obtained here
       setState(() {
         _token = event;
       });
       if (event != null &amp;&amp; event.isNotEmpty) {
         Synerise.notifications.registerForNotifications(
           event,
           mobileAgreement: true,
           onSuccess: () {},
           onError: (error) {},
         );
         print("TokenEvent: " + _token);
       }
     }</code></pre>

3. Add a listener to trigger `getToken()` from the Huawei push library whenever the [`onRegistrationRequired`](/developers/mobile-sdk/listeners-and-delegates/flutter-listeners#notifications-listener) callback is called:  
    
   <pre><code class="language-js">Synerise.notifications.listener((listener) {
         listener.onRegistrationRequired = () {
           getToken();
         };
       });</code></pre>

4. Add the `onMessageReceived` callback from the Huawei push library and pass the data to Synerise SDK:  
    
   <pre><code class="language-js">Future&lt;void&gt; _onMessageReceived(RemoteMessage remoteMessage) async {
       // Called when a data message is received
       Map&lt;String, String&gt;? data = remoteMessage.getDataOfMap;
       if (data != null) {
         bool isSyneriseNotification =
         await Synerise.notifications.isSyneriseNotification(data);
         if (isSyneriseNotification == true) {
           Synerise.notifications.handleNotification(data);
           bool isSyneriseNotificationEncrypted = await Synerise.notifications
               .isNotificationEncrypted(data);
           if (isSyneriseNotificationEncrypted) {
             Map decryptedPayload =
             await Synerise.notifications.decryptNotification(data);
             developer.log(decryptedPayload.toString());
           }
         }
       }
     }</code></pre>

5. To make sure your callbacks work, use streams:  
    
   <pre><code class="language-js">Future&lt;void&gt; initTokenStream() async {
       if (!mounted) return;
       Push.getTokenStream.listen(_onTokenEvent, onError: _onTokenError);
     }

     void getToken() {
       // Call this method to request for a token
       Push.getToken("");
     }

     Future&lt;void&gt; initMessageStream() async {
       if (!mounted) return;
       Push.onMessageReceivedStream
           .listen(_onMessageReceived, onError: _onMessageReceiveError);
     }</code></pre>


## Links and Deep Links

In order to implement links and deep links, refer to [this](/developers/mobile-sdk/campaigns/action-handling#handling-actions-from-campaigns-in-android) instruction.

## Configuring notification encryption

Instructions for encrypting push notifications are available [here](/developers/mobile-sdk/configuring-push-notifications/flutter#configure-notification-encryption).