Huawei integration in Flutter SDK

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”.

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.

Tip: More information about Synerise.initializer is available in “Initialization”.

Implementing Huawei notifications in applications

  1. Add the Huawei push library as a dependency and integrate it: 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 method:
    void _onTokenEvent(String event) {
        // Requested tokens can be obtained here
        setState(() {
          _token = event;
        });
        if (event != null && event.isNotEmpty) {
          Synerise.notifications.registerForNotifications(
            event,
            mobileAgreement: true,
            onSuccess: () {},
            onError: (error) {},
          );
          print("TokenEvent: " + _token);
        }
      }
        
    
  3. Add a listener to trigger getToken() from the Huawei push library whenever the onRegistrationRequired callback is called:
    Synerise.notifications.listener((listener) {
          listener.onRegistrationRequired = () {
            getToken();
          };
        });
        
    
  4. Add the onMessageReceived callback from the Huawei push library and pass the data to Synerise SDK:
    Future<void> _onMessageReceived(RemoteMessage remoteMessage) async {
        // Called when a data message is received
        Map<String, String>? 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());
            }
          }
        }
      }
        
    
  5. To make sure your callbacks work, use streams:
    Future<void> initTokenStream() async {
        if (!mounted) return;
        Push.getTokenStream.listen(_onTokenEvent, onError: _onTokenError);
      }
    
      void getToken() {
        // Call this method to request for a token
        Push.getToken("");
      }
    
      Future<void> initMessageStream() async {
        if (!mounted) return;
        Push.onMessageReceivedStream
            .listen(_onMessageReceived, onError: _onMessageReceiveError);
      }
        
    

In order to implement links and deep links, refer to this instruction.

Configuring notification encryption

Instructions for encrypting push notifications are available here.

😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker