Skip to main content

Huawei SDK Setup

If you wish to use Huawei Push services (via Huawei Mobile Services (HMS)) you will need to do some additional changes to your installation.

We will assume you have already setup your OneSignal account and have your App ID. If not see the setup section.

Authorising OneSignal

Follow the instructions here to authorise OneSignal to connect to your Huawei application.

Huawei Configuration File

Download the agconnect-services.json file:

  • From the AppGallery Connect Project List select your app.

  • Ensure you have added your certificate SHA fingerprint to your app configuration.

  • Click on the "agconnect-services.json" button to download this file.

  • Place this file at the root of your application and ensure it is packaged.

Dependencies

There are two cases to consider here,

  • using Huawei only with no Firebase dependencies
  • adding HMS alongside the Firebase implementation

Alongside Firebase

This case is useful if you wish to deploy your application to both Huawei devices and devices that have access to Google Play Services. OneSignal will favour Firebase in any situations where both are available.

To support this case, it is simply a matter of following the standard installation and adding the HMS dependencies.

Using apm this can be done via the following:

apm install com.huawei.hms.push

This extension will install some required asset files to assets/android. You must ensure all the files in that directory are packaged with your application at the root level.

Next you will need to add the additional OneSignal HMS manifest additions manually here by creating a custom configuration:

apm generate config android

Edit the file created at config/android/AndroidManifest.xml and ensure it contains the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="33"/>

<application>

<service
android:name="com.distriqt.extension.pushnotifications.onesignal.OneSignalHMSService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>

<activity
android:name="com.onesignal.notifications.activities.NotificationOpenedActivityHMS"
android:exported="true"
android:noHistory="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>

</application>

</manifest>

Then regenerate your application descriptor.

apm generate app-descriptor

Huawei Only

If you need to solely use HMS you will need to uninstall the Firebase and Google Play Services dependencies and swap to Huawei Mobile Services.

The simplest way to do this is to remove the com.distriqt.PushNotifications-OneSignal package and install the com.distriqt.PushNotifications-OneSignalHMS package.

apm uninstall com.distriqt.PushNotifications-OneSignal
apm install com.distriqt.PushNotifications-OneSignalHMS

Then regenerate your application descriptor.

apm generate app-descriptor
note

Ensure that any of the com.google.firebase.* and com.distriqt.playservices.* extensions were removed from your extension list in your application descriptor.

If you have other services relying on playservices or firebase they may still remain and can cause issues with OneSignal.

Initialise HMS

There is one small code addition required, which is simply to initialise HMS to ensure the configuration is read from your agconnect services json file. We suggest doing this before initilaising the Push Notifications extension and setting up your service.

Firstly add the import:

import com.distriqt.extension.hms.base.Base;

Then call initialise():

var success:Boolean = Base.instance.initialise();

This will return true if the json file was found and loaded correctly.