当前位置:网站首页>[FAQ] how do HMS core push services and local creation notification messages overlap each other?
[FAQ] how do HMS core push services and local creation notification messages overlap each other?
2022-04-22 10:22:00 【HMS Core】
We know , Use alone HMS Core Push service Or create notification messages locally , Can realize the coverage of notification messages , The methods are :
1、 Create notification messages locally ( Local notification message )
adopt notificationManager.notify(notifyId, notification) Set the same notifyId That is to say .
2、HMS Core Push service Send a notification message ( Huawei push notification message for short )
Use HMS Core Push service api Message sent , By setting notify_id, That is, the unique identification of each message when the notification is displayed .notify_id When not carried or set -1 when ,Push NC Automatically generate a unique identifier for each message , Messages will not be overwritten ; Set the same notifyId, You can realize the function of covering the previous message with a new message .
** Although the above two implementations can be used alone , But sometimes there are scenes , Local notification messages and Huawei push notification messages can overlap each other .** For example, push notification messages through Huawei , Remind users of changes in the price of goods of interest , If the user has purchased , At this time, the local notification message can be set to be the same as the Huawei push notification message notify_id value , Update the recommendation message to the logistics information of the commodity order , Meet the special use scenarios of the application .
Step summary
1、 Huawei push notification message , The title is : Huawei push service test message , Content : The price of the goods you subscribe to changes ,notify_id:10;
2、 Local notification message , title : Test local notification entry channels localNotification, Content :\uD83D\uDCE6 You have a courier coming at a high speed \uD83D\uDE80, Click to view the express information , You can also set the receiving method >>>,notifyId:10;
3、 Huawei push notification message , title : Huawei push service test message , Content : The goods you purchased have been signed for ,notify_id:10.
Detailed process
First , Developers need to access push services , Please refer to The official link
After the client accesses the push service , Get... Through the client Push Token, And then you can use Push Returned by the server Push Token Push messages to applications .
HMS Core Push server sample code :
{ "validate_only": false, "message": { "android": { "notification": { "click_action": { "type": 3 }, "notify_id": 10 } }, "notification": { "body": " The price of the goods you subscribe to changes ", "title": " Huawei push service test message " }, "token": ["your push token"] }}
Local application client sample code (Kotlin):
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
// Create a send message channel ,“localNotification”
var channelId = "localNotification" if(Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){ var importance = NotificationManager.IMPORTANCE_HIGH; var notificationChannel = NotificationChannel(channelId,channelId,importance) notificationChannel.enableVibration(true) notificationChannel.setShowBadge(true) if(manager != null){ manager.createNotificationChannel(notificationChannel) } }
// Send message to channel channelId
``` val mBuilder = NotificationCompat.Builder(this@MainActivity,channelId) mBuilder.setContentTitle(" Test local notification entry channels $channelId") // Set notification bar title .setContentText("\uD83D\uDCE6 You have a courier coming at a high speed \uD83D\uDE80, Click to view the express information , You can also set the receiving method >>>") .setWhen(System.currentTimeMillis()) .setPriority(Notification.PRIORITY_DEFAULT) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_VIBRATE) .setSmallIcon(R.mipmap.ic_launcher_round) val notification = mBuilder.build() manager.notify(10, notification) // there notifyId With Huawei pushing notification messages notify_id Same value , To achieve the same notifyId/notify_id Overwrite the notification message ```
The effect is as follows :

From the above effect example , It can be seen that , By keeping notifyId And notify_id Same value , The local notification message can overwrite the previous Huawei push notification message , meanwhile , Huawei push notification message can also overwrite the previous local notification message , Thus, the mutual coverage function of local notification message and Huawei push notification can be realized .
matters needing attention
When creating a notification message locally , Such as notificationManager.notify(notifyId, notification), Set up notifyId With Huawei pushing notification messages notify_id Field values are the same , You can realize the mutual coverage of local notification messages and Huawei push notification messages .
It should be noted that , The same application settings are the same notifyId/notify_id Notice of , Cover according to the display order , That is, the message displayed after overwrites the message displayed before . meanwhile , Huawei pushes notify_id Field , Need to meet EMUI Version in 9.1.0 And above 、 The push service application version is in 9.1.1 And above , To take effect .
Learn more >>
visit Official website of Huawei developer Alliance
obtain Development guidance document
Huawei mobile service open source warehouse address :GitHub、Gitee
Pay attention to our , The first time to understand HMS Core Latest technical information ~
版权声明
本文为[HMS Core]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221018263017.html
边栏推荐
- 01背包问题——以及变形问题
- Linux 7 silent installation oracle12c reports an error [fatal] [ins-35344] the value is not specified
- Tensorflow Experiment 4 -- Boston house price forecast
- Meituan side: have you used jstat, jmap, mat in the production time? Can you give me a practical example?
- Summary of JS page refresh methods
- Android被爆安全漏洞 根源是苹果的无损音频编解码器
- 003-MySQL索引
- 来文章啦~分享压缩和解压文件【在线网站】
- MySQL进阶之表的增删改查
- 「译文」给讨厌YAML的人的10个写YAML的建议
猜你喜欢

Film online ticket purchase system based on SSM

NavigationView的使用

DataGuard (ADG) spare database moves (migrates) data files

Tree DP - p1122 maximum subtree sum

oracle19. 3 upgrade to 19.6

Grpc experience of multilingual communication foundation

A case of MySQL implicit conversion

5.嵌入式控制器(Embedded Controller,EC)学习 PS/2协议

idea 线程池debug断点跳不进去
![idea写sparksql程序local[*]模式可以运行,提交到spark yarn运行出现ClassNotFoundException](/img/67/065e2b047ba26d67924b458141d73b.png)
idea写sparksql程序local[*]模式可以运行,提交到spark yarn运行出现ClassNotFoundException
随机推荐
UKUI3 支持 openEuler 22.03 LTS
【HLS】可变帧率和固定帧率拉流
dataguard (ADG)备库移动(迁移)数据文件
*CTF 2022 Reverse Writeup
Dext diagnostic database supporting AUTOSAR classic and adaptive platform
《MySQL 是怎样运行的:从根儿上理解 MySQL 》优质笔记
golang 时间格式化
Analysis of image lazy loading (three implementation methods and two optimization methods)
Idea writes sparksql program in local [*] mode, which can be run. Classnotfoundexception occurs when it is submitted to spark yarn for running
Ctyunos scale deployment of China Telecom and jointly build Tianyi cloud digital base with openeuler
TC397 EVADC
build perl from source
Glide设置圆角图片(支持自定义圆角位置)
The headline interview actually told me about semaphore for half an hour
SPA首屏加载优化
Qt关于信号槽连接出现的一些问题记录
【QT小记】使用QPainter绘制各种基本图形
Google Earth engine (GEE) -- aggregate grid population data
Three minute quick understanding of interactive graffiti
美团一面:有在⼯作时间中使⽤过 jstat, jmap, mat⼯具吗? 能给⼀个实际的例⼦说明⼀下吗?