Huawei Push Kit SDK Integration

Quick Steps Guidelines

Step 1: Create A Huawei Push Message Configuration

Create and configure a project on the Huawei Developers Console.

Step 2: Integrate SDK

Add the configurations in the step to your build.gradle file.

Step 3: Initialize Netmera

Add the code to the onCreate() method of the class that extends android.app.Application.

Step 4: Enable Pop-up Presentation

Enable pop-up notifications

Step 5: Huawei Message Receipt

For the final step, make sure to complete the steps in Huawei / Message Receipt.

Huawei SDK integration completed 👏

Step 1: Create A Huawei Push Message Configuration

Netmera utilizes Huawei Push Message to deliver push messages to Android devices. Therefore, it's essential to create and configure a project on the Huawei Developers Console. Follow these steps for Huawei Push Kit Configuration.

Huawei Push Kit Configuration Steps

  1. Begin by following Huawei's guides for setting up your application using the following links:

  2. Enable PushKit first within the Huawei panel.

  1. Add the SHA256 fingerprint value of your application to the Huawei Console.

  1. Download the agconnect-services.json file and place it in your app's folder.

  1. After completing the configuration, you will obtain the values of the App Secret Key and App_ID for your project. These values need to be added to the Netmera Dashboard under Developers > Push Backends > Huawei. Additionally, the App_ID should be used during client initialization.

The App ID and App Secret Key:

The app ID and app secret key information corresponds to the client ID and client secret key generated under the project for the app.

Step 2: Integrate SDK

The Netmera Android SDK is available through the Maven repository. To integrate it into your project, follow these steps:

Modify your build.gradle file:

Add the following configurations to your build.gradle file. AndroidManifest and other resource configurations are automatically handled by the Android Gradle build tool.

buildscript {
    repositories {
        google()
        maven {url 'http://developer.huawei.com/repo/'
    }
    dependencies {

    classpath 'com.android.tools.build:gradle:4.2.2'
    classpath 'com.huawei.agconnect:agcp:1.6.3.300'    }
}

  allprojects {
    repositories {
        google()
        maven {url 'http://developer.huawei.com/repo/'}
        maven { url "http://release.netmera.com/release/android" }
    }
}

Add Netmera dependency:

In your build.gradle (:app) file, include the Netmera dependency within the dependencies section:

dependencies {


       implementation 'com.netmera:nmcore:3.9.11'
       implementation 'com.netmera:nmhms:3.9.5'
}

//must be add the bottom of app's build gradle
apply plugin: 'com.huawei.agconnect'

Important Note for Obfuscation:

If you choose to obfuscate your code, you don't need to add any specific rules. Netmera's SDK seamlessly integrates with your obfuscated code.

Step 3: Initialize Netmera

To initialize Netmera, add the following code to the onCreate() method of the class that extends android.app.Application. If you don't have such a class, create it and add it to your AndroidManifest file using the android:name attribute within the application tag.

@Override public void onCreate() {
    super.onCreate();
  NMInitializer.initializeComponents(this);

AppInitializer.getInstance(this).initializeComponent(NMHMSProviderInitializer.class);

NetmeraConfiguration.Builder configBuilder = new NetmeraConfiguration.Builder();

configBuilder.baseUrl(baseUrl).apiKey(apiKey)

//If there is an on-premise installation, you must call the following method.
//Netmera.setBaseUrl("YOUR PANEL DOMAIN URL")


    .huaweiSenderId(PropertiesUtil.hmsSenderId)

    .logging(true)

    .nmInAppMessageActionCallbacks(new NGInAppMessageActionCallbacks())

    .nmPushActionCallbacks(new NGPushActionCallbacks());

Netmera.init(configBuilder.build(this));

}

Please make sure you get the API key value from the relevant panel

YOUR_SDK_API_KEY: You can get the api key from Developers > API > SDK API Key from your web panel.

Enabling Logging:

You can also enable logging by adding the following line of code to the onCreate() method of your class that extends android.app.Application:

Netmera.logging(true);

Step 4: Enable Pop-up Presentation

Pop-up notifications are automatically displayed within the app through an internal activity class in Netmera. However, to prevent disruption to your app's flow at launch, this feature is disabled by default. It is essential to call the following method in your main activity, ensuring not to add it to a splash activity if you have one:

To enable pop-up notifications, follow these steps:

  1. In your main activity, after it has started, add the following code:

//let Netmera to be able to show popup
Netmera.enablePopupPresentation();

Please ensure that you do not include this code in a splash activity if your app has one.

Show Netmera's push with another HMS integration

If you have your own Huawei Mobile Services (HMS) integration and wish to integrate Netmera's push notifications, consider implementing the onNetmeraPushMessageReceived method in your onMessageReceived function. Additionally, when the token is renewed, ensure to call this method to forward it to Netmera(Netmera.onNetmeraNewToken(token)

Here's an example of implementing this in your class that extends HMSMessageService:

public class PushMessaging extends HMSMessageService {

  @Override
  public void onMessageReceived(RemoteMessage p0) {
       super.onMessageReceived(p0)

       Netmera.onNetmeraPushMessageReceived(p0)
   }


 @Override
    public void onNewToken(String token) {
        super.onNewToken(token);

      Netmera.onNetmeraNewToken(token);
    }
}

Step 5: Huawei Message Receipt

To ensure the successful sending of push messages, please follow the steps outlined in the "Huawei Message Receipt" guide. Complete all the necessary steps as described to ensure your push messages are sent effectively.

Huawei Message Receipt:

Make sure to complete the steps in Huawei / Message Receipt to send push messages.

Huawei Push Kit SDK integration completed 👍

Huawei SDK integration has been successfully completed, and your devices are now ready to receive the following types of push notifications sent via the Netmera Dashboard:

  1. Standard Push Notifications

  2. Interactive Push Notifications (If you've configured and published them using the Dashboard)

  3. Push Notifications with Web View Content

  4. Push Notifications with Deeplinks (If your application supports URL Scheme-based deeplinks and you've configured the application's URL Scheme in the Dashboard.)

Last updated