Please follow the instructions to enable push on the project and your AppGallery Connect console (Also you will need to enable push notification on firebase). Then add agconnect-services.json to root directory instructions.
For this project, you will need to use the following plugins for Cordova.
-CordovaHMSGMSCheckPlugin: Check if HMS or GMS is avalaible on the phone.
-cordova-plugin-hms-push-4.0.3: Huawei Push kit pluging.
-FCM: Firebase plugin
-HTTP: Http requests plugin
Install the android platform
ionic cordova platform add android
Install the plugins using the following command
ionic cordova plugin add CORDOVA_PLUGIN_PATH
gms-service.service.ts : Replace the API_KEY_SERVER_PUSH with yours given by Firebase
...
const API_KEY_SERVER_PUSH="<Replace-with-your-server-key>";
const API_PUSH_SEND = "https://fcm.googleapis.com/fcm/send";
hms-service.service.ts: replace the credentials with the ones given by the App gallery connect on your App.
...
const postData = {
method: 'post',
data: {
//client secret and client id extracted from AppGallery console
grant_type: "client_credentials",
client_secret: '<your client secret>',
client_id: '<your client id>'
},
headers: { 'content-type': 'application/x-www-form-urlencoded' }
}
...
Change the path over the API_PUSH_SEND to include your App id in the URL.
const API_TOKEN = "https://oauth-login.cloud.huawei.com/oauth2/v2/token";
const API_PUSH_SEND = "https://push-api.cloud.huawei.com/v1/<your_app_id>/messages:send";
Run the project:
ionic cordova build android
ionic cordova run android