Giter Site home page Giter Site logo

halilozel1903 / huaweipushkitapp Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 4.0 7.03 MB

An Android application related to Huawei Push Kit 🚨 πŸ“© πŸ“¨

Home Page: https://halilozel1903.medium.com

Kotlin 100.00%
push-notifications huawei huawei-mobile-services huawei-push push-kit push-notification push-notification-android push-notification-server push-notification-client huawei-devices

huaweipushkitapp's Introduction

Huawei Push Kit πŸ› 

Hello everyone, Today we will learn Huawei Push Kit.

Note : Used within the Huawei Map Kit application. Similar steps exist.

https://github.com/halilozel1903/HuaweiMapKitApp

What is Huawei Push Kit ⁉️

Huawei

HUAWEI Push Kit is a messaging service provided for you. It establishes a messaging channel from the cloud to devices. By integrating Push Kit, you can send messages to your apps on users' devices in real time. This helps you maintain closer ties with users and increases user awareness of and engagement with your apps. The following figure shows the process of sending messages from the cloud to devices.

Currently, Push Kit has been supported in mobile phones, tablets, HUAWEI Vision, HUAWEI Watch, and Volvo and Dongfeng Sokon head units.

For more : https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-sdk-introduction-0000001050158633

How to use Huawei Push Kit πŸ“Œ

You can follow the steps in this blog post.

The steps we need to integrate for Push Kit are as follows.

  • We activate Push Kit from the Manage API section

PushKitIntegration

  • We are making Push Kit integrations.

PushKitEnable

  • We choose Germany from the data storage location section.

PushKitLocation

  • We fill in the fields below for the notification example.

PushKitLocation

  • When we click the test effect button, it will ask us for tokens.

In this step, we will be able to learn the token value we need when we integrate the Push Kit into the application.

  • Push Kit added in build.gradle(:app)
implementation 'com.huawei.hms:push:6.1.0.300'
  • We create a function in Main Activity. We define an instance to get the token value.
       private fun getToken() {
           object : Thread() {
               override fun run() {
                   try {
                       val appId = AGConnectOptionsBuilder().build(this@MainActivity)
                           .getString("client/app_id")
                       val token = HmsInstanceId.getInstance(this@MainActivity)
                           .getToken(appId, "HCM")
                       Log.i("PUSH", "getToken() token: $token")
                   } catch (e: ApiException) {
                       Log.e("PUSH", "getToken() failure: ${e.message}")
                   }
               }
           }.start()
       }

Run the application. The token value is displayed in the log section.

HuaweiPushKToken

Put this token value in the field in the Push Kit test.

HuaweiPushTest

It will test the application with Cloud Debugging.You can run the application by following the below document.

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-clouddebug-realtimedebug

We have done all the necessary actions. Congratulations πŸ₯³ You have developed the first Huawei Push Kit application.

Testing with Postman πŸ“¨

You can test the application with Postman by following the steps below.

  • Download the json file located in the url below.

https://gist.github.com/halilozel1903/a9bc9c09bd00ac490fbb26d4ffeefa38

  • Open Postman. Import the file. (Postman -> file -> import) After you import, we can send 3 requests

  • Replace the app_id and app_secret values in the body with the App ID and App secret values on the application home page of the Huawei Console. Replace the fields in the image below with the values in your own project.

huaweiPushGallery

  • Change the app_id value in the link in the Send notification and Send data message files with the App ID on the application page in the console.

  • Open the Send notification and Send data message files and replace the push_token part in the Body with the token we get from the application logs.

PushKitToken

  • Open the Get access token file and click the Send button to get access token. The access token is valid for 3600 seconds and you need to renew it later.

huaweiPushAccessToken

  • Open the Send notification and Send data message file and replace the access_token part in Authorization with the access token we got in before step. Don't forget to delete this characters \ in the access token.

huaweiPushSend

When we follow the steps above and make a request, we will have successfully seen our notifications on the screen.

Recourses πŸ“š

  1. https://developer.huawei.com/consumer/en/codelab/HMSPushKit/

  2. https://developer.huawei.com/consumer/en/hms/huawei-pushkit/

  3. https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/push-console

Donation πŸ’Έ

If this project help πŸ’ you to develop, you can give me a cup of coffee. β˜•

"Buy Me A Coffee"

License ℹ️

MIT License

Copyright (c) 2022 Halil OZEL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

huaweipushkitapp's People

Contributors

halilozel1903 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

huaweipushkitapp's Issues

send notification to subscribe Topic instead token

hey thanks for ur example.
i'm trying to send notification to my users using topic instead of token
when i send it in HMS console all things good but it’s not working in the api.
response said that all's was good but i didn’t got nothing in my phone.
any help please πŸ™
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.