We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
SamplesPush KitClient Sample Code

Client Sample Code

Android Studio

If you are using Android Studio, you can choose to use the Java or Kotlin sample code as you need. The sample code provides a demo project that demonstrates how to call open APIs of Push Kit. Guided by the demo, you will learn how to:

  • Apply for and delete an AAID.
  • Apply for and delete a token.
  • Subscribe to and unsubscribe from topics.
  • Configure whether to display notification messages.
  • Receive notification messages or data messages sent from the Push Kit server.
  • Tap notification messages to go to the app home page or specified pages.
Expand

Sample Code

Find It on Gitee

Find It on GitHub

Android Studio sample code (including Java and Kotlin)

Click here

Click here

NOTE

Before using the sample code, read the README file in the sample project carefully. Run the sample code only after you complete the following operations:

  1. Sign in to AppGallery Connect, download the agconnect-services.json file of your app, and copy the file to the app directory of the sample project.

  2. Open the build.gradle file in the sample project, and change the value of applicationId to your app package name.

DevEco Studio

If you are using DevEco, you can choose to use the HarmonyOS (Java) sample code as you need. The sample code provides a demo project that demonstrates how to call open APIs of Push Kit. Guided by the demo, you will learn how to:

  • Apply for and delete an AAID.
  • Apply for and delete a token.
  • Receive notification messages or data messages sent from the Push Kit server.
  • Tap notification messages to go to the app home page or specified pages.
Expand

Sample Code

Find It on Gitee

Find It on GitHub

DevEco Studio sample code (Java)

Click here

Click here

NOTE

Before using the sample code, read the README file in the sample project carefully.

Web App

After downloading and decompressing the sample code package, you are advised to read the README.md file in the project first. This sample includes the following functions:

  • Apply for a token.
  • Receive messages in the foreground.
  • Receive messages in the background.
Expand

Sample Code

Download Package

Web app sample code

huawei-push-client-webpush-demo.zip

Search in Samples
Enter a keyword.