- 1. Introduction
- 2. Installation Guide
- 3. Configuration and Description
- 4. Questions or Issues
- 5. Licensing and Terms
This demo application demonstrates the usage of HMS Push Cordova Plugin.
Before you get started, you must register as a HUAWEI Developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.
Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:
- Sign in to AppGallery Connect and select My projects.
- Select your project from the project list or create a new one by clicking the Add Project button.
- Go to Project Setting > General information, and click Add app.
- If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.
- On the Add app page, enter the app information, and click OK.
A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core (APK) through the HMS SDK. Before using the HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in the AppGallery Connect. You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.
- Sign in to AppGallery Connect and select your project from My Projects. Then go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA-256 certificate fingerprint.
- After completing the configuration, click OK to save the changes. (Check mark icon)
- In the same page, click agconnect-services.json button to download the configuration file.
-
Install Ionic CLI and other required tools if haven't done before.
npm install -g @ionic/cli cordova-res native-run
-
Open the demo project's root directory.
-
Install project dependencies.
npm install
-
Enable the Cordova integration if haven't done before.
ionic integrations enable cordova
-
Update the widget
id
property which is specified in theconfig.xml
file. -
Add the Android platform to the project if haven't done before.
ionic cordova platform add android
-
Install
HMS Push Cordova Plugin
to the project. You can either install the plugin throughnpm
or bydownloading from HMS Core Plugin page
.a. Run the following command in the root directory of your project to install it through npm.
ionic cordova plugin add @hmscore/cordova-plugin-hms-push
b. Or download the plugin from Plugin > Push Kit > Cordova Plugin page and run the following command in the root directory of your project to install it manually.
ionic cordova plugin add <hms_cordova_push_plugin_path>
-
If you want to enable Ionic Native support then run the following command.
npm install @awesome-cordova-plugins/core @hmscore/ionic-native-hms-push
-
Copy
agconnect-services.json
file to<project_root>/android/app
directory. -
Add
keystore(.jks)
andbuild.json
files to your project's root directory.
-
You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.
-
Fill
build.json
file according to your keystore information. For example:{ "android": { "debug": { "keystore": "<keystore_file>.jks", "storePassword": "<keystore_password>", "alias": "<key_alias>", "password": "<key_password>" }, "release": { "keystore": "<keystore_file>.jks", "storePassword": "<keystore_password>", "alias": "<key_alias>", "password": "<key_password>" } } }
-
Run the application.
ionic cordova run android --device
-
Enable the Capacitor integration if haven't done before.
ionic integrations enable capacitor
-
Update the widget
appId
property which is specified in thecapacitor.config.json
file. -
Install
HMS Push Cordova Plugin
to the project. You can either install the plugin throughnpm
or bydownloading from HMS Core Plugin page
.a. Run the following command in the root directory of your project to install it through npm.
npm install @hmscore/cordova-plugin-hms-push
b. Or download the Plugin from Plugin > Push Kit > Cordova Plugin page and run the following command in the root directory of your project to install it manually.
npm install <hms_cordova_push_plugin_path>
-
If you want to enable Ionic Native support then run the following command.
npm install @awesome-cordova-plugins/core @hmscore/ionic-native-hms-push
-
Build Ionic app to generate resource files.
ionic build
-
Add the Android platform to the project if haven't done before.
npx cap add android
-
Copy
agconnect-services.json
file to<project_root>/android/app
directory. -
Copy
keystore(.jks)
file to<project_root>/android/app
directory.
- You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.
- Open the
build.gradle
file in the<project_root>/android/app
directory.
-
Add
signingConfigs
entry to android according to your keystore information. -
Enable
signingConfig
configuration to debug and release flavors. -
Apply
com.huawei.agconnect
plugin.... android { ... // Add signingConfigs according to your keystore information signingConfigs { config { storeFile file('<keystore_file>.jks') storePassword '<keystore_password>' keyAlias '<key_alias>' keyPassword '<key_password>' } } buildTypes { debug { signingConfig signingConfigs.config // Enable signingConfig in debug flavor } release { signingConfig signingConfigs.config // Enable signingConfig in release flavor minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } ... apply plugin: 'com.huawei.agconnect' // Apply com.huawei.agconnect plugin. This line must be added to the end of the file.
-
Open the
build.gradle
file in the<project_root>/android
directory. Add Huawei's maven repositories and agconnect classpath to the file.buildscript { repositories { /* <Other repositories> */ maven { url 'https://developer.huawei.com/repo/' } } dependencies { /* <Other dependencies> */ classpath 'com.huawei.agconnect:agcp:1.9.1.301' } } /* <Other build.gradle entries> */ allprojects { repositories { /* <Other repositories> */ maven { url 'https://developer.huawei.com/repo/' } } }
-
Open the project in Android Studio and run it.
npx cap open android
If you have questions about how to use HMS samples, try the following options:
- Stack Overflow is the best
place for any programming questions. Be sure to tag your question
with
huawei-mobile-services
. - GitHub is the official repository for these plugins, You can open an issue or submit your ideas.
- Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
- Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.
If you run into a bug in our samples, please submit an issue to the GitHub repository.
HMS Push Cordova Plugin is licensed under the Apache 2.0 license.