Push notifications for both Google and Huawei phones by Pushe

Mahdi Malvandi
3 min readNov 18, 2020

You’ve probably heard that since Huawei (and some other Chinese brands) are banned by Google, they can not use any Google specific services. Therefore, Huawei has introduced it’s own service called “Huawei Mobile services”.

Pushe, Fcm and Huawei logos

One of those services that we’re focusing on in this article is “Push notifications”, which is provided by Firebase cloud messaging on devices that are shipped with Google apps and by PushKit for Huawei and other devices not featuring Google apps.

In order to be able to send push notifications to all of your users, their devices must be featured with either Google Play Services or HMS Core.

Problem

Since you have two services to work with, for only one task, you need to put extra effort to maintain them. So you need to:

  • Signup in Firebase and Huawei app gallery
  • Create and register an app and apply for Push notifications
  • Implement and setup both FCM and HMS client libraries
  • Send notifications in both consoles in order to cover all users

So doing all these will eventually make the process even harder to maintain and can also lead into problems and mistakes.

That’s how you will describe yourself after

Issue of Pushe

On Android, Pushe uses Firebase cloud messaging to interact with users. Firebase uses Google play services to create connection with users.

This means, devices without Google play services can not interact with Firebase and so, Pushe can not interact with users.

Solution of Pushe

As of Pushe for Android version 2.4.0 , Pushe introduces a new module hms that will be responsible for handing push notifications for Huawei devices (Using HMS core).

So by using Pushe you only need to provide credentials of both consoles and Pushe will take care of the rest of the work.

So if device has Google play service, the fcm module rises and handles the interaction and if instead, HMS Core is available, hms module will take the wheel.

How do hms and fcm work together?

These steps will be taken at the startup of the library:

  1. Core module allows hms and fcm to start initializing.
  2. fcm will check if Google play is available:

If isFirebaseAvailable was true, it will register itself as a Courier that can handle input and output. Otherwise, no operations will be done by fcm.

3. hms module, much like fcm, will check for availability of HMS service:

and it will also register itself as a Courier if isHmsAvailable returned True.

4. Core module starts registration with server. It check for available couriers registered. It will tell them to fetch for token. One of the following may happen:

  • If No couriers are available, an error will be thrown
  • If One courier is registered, it will be used for future usages
  • If Multiple couriers are registered (In case both Google play and HMS core are installed on the device), it will select one depending on the priority that is specified before. Using pushe_preffered_service manifest meta-data, you can select either fcm or hms to specify the prior service in case both were available (Default is fcm)

So to summarize, Pushe will try to attach to different services and will support even more services with the favor of modularization.

And here’s a sample to help you start:

--

--