当前位置:网站首页>【开发者必看】【push kit】推送服务典型问题合集3
【开发者必看】【push kit】推送服务典型问题合集3
2022-07-30 17:43:00 【华为开发者论坛】
【问题描述1】
无法获取 Push Token,如何解决?
【解决方案】
1.检查Push推送API权益是否开启。
2.检查AGC控制台应用的对应信息是否正确。
3.EMUI 9.0.0的Push Token返回请以onNewToken返回信息为准,确保在清单文件中配置了对应的服务类
4.清理hms core缓存后重试(找到设置-应用-应用管理-搜索hms core,清理缓存或点击右上角三个点按钮,卸载更新至最新版后重试)
5.卸载重装应用后再重新获取Push Token
【问题描述2】
导致 Push Token 变化的原因有哪些?
【解决方案】
Token会在包括但不限于下述场景中发生变化:
1.应用卸载重装。
2.应用调用注销Token方法。
3.用户恢复出厂设置。
4.清除应用数据,重新进入应用。
注意事项:token是变化的
1.应用不要固定判断Token长度,因为后续长度可变。
2.应用的Token要定期更新(建议应用每次启动的时候都获取Token,如果发现和上次取到的不同,需要将新获取的Token上报到自己的服务器)。
3.请勿使用Token跟踪标记用户。
【问题描述3】
通过端侧方法,修改桌面角标数,当角标数为0时,角标不显示
【解决方案】
private void changeBadge(Application application, int number){ String packageName = application.getPackageName(); Bundle bundle = new Bundle(); bundle.putString("package", packageName); ComponentName launchClassComponent = application.getPackageManager().getLaunchIntentForPackage(packageName).getComponent(); if (launchClassComponent == null) { return; } String launchClassName = launchClassComponent.getClassName(); bundle.putString("class", launchClassName); bundle.putInt("badgenumber", number); try { Bundle result = application.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, bundle); Log.i(TAG, "clearBadge result = " + result); } catch (Exception e) { Log.i(TAG, "clearBadge error "); } }
【问题描述4】
通过以下代码,在端侧手动增加消息通知渠道
【解决方案】
@RequiresApi(api = Build.VERSION_CODES.O) private void addNotificationChannel(){ NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //创建通知渠道实例 //并为它设置属性 //通知渠道的ID,随便写 String id = "my_channel_01"; //用户可以看到的通知渠道的名字,R.string.app_name就是strings.xml文件的参数,自定义一个就好了 CharSequence name = getString(R.string.app_name); //用户可看到的通知描述 String description = getString(R.string.app_name); //构建NotificationChannel实例 NotificationChannel notificationChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH); //配置通知渠道的属性 notificationChannel.setDescription(description); //设置通知出现时的闪光灯 notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); //设置通知出现时的震动 notificationChannel.enableVibration(true); notificationChannel.setShowBadge(false); notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 100}); //在notificationManager中创建通知渠道 manager.createNotificationChannel(notificationChannel); //蓝色字是个新方法,旧的被api放弃了 Notification notification = new NotificationCompat.Builder(this, id) .setContentTitle("标题") .setContentText("内容666666666666666666666666666") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_launcher_background) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.btn_round_background)) .build(); manager.notify(1, notification); }
欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
边栏推荐
- Mysql brush dirty several scenarios and related parameters
- 数据库系统原理与应用教程(069)—— MySQL 练习题:操作题 95-100(十三):分组查询与聚合函数的使用
- [Solved] The problem that Unity Hub fails to obtain a license or does not respond and cannot develop
- Graph Attention Mechanism
- MySQL中的存储过程(详细篇)
- 什么是无损检测设备?
- reporter undercover
- What ARC does at compile time and runtime
- 千亿级、大规模:腾讯超大 Apache Pulsar 集群性能调优实践
- JVM 上数据处理语言的竞争:Kotlin, Scala 和 SPL
猜你喜欢

Shell implementation based on stm32

高级语言垃圾回收思路和如何减少性能影响原理分析

开源盛宴ApacheCon Asia 2022即将开幕,精彩不容错过!

un7.30:linux——如何在docker容器中安装MySQL?

Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions

weiit新零售小程序如何探索数字化门店的破局之路

图卷积神经网络的数学原理——谱图理论和傅里叶变换初探

This year..I sincerely recommend the professional engineer to upgrade to the book!

一个 15 年 SAP ABAP 开发人员分享的 SAPGUI 一些个性化设置和实用小技巧试读版

这玩意儿都能优化?果然是细节都在魔鬼里。
随机推荐
宽带射频放大器OA4SMM4(1)
一个 15 年 SAP ABAP 开发人员分享的 SAPGUI 一些个性化设置和实用小技巧试读版
躲避雪糕刺客?通过爬虫爬取雪糕价格
论文阅读之《DeepIlluminance: Contextual IlluminanceEstimation via Deep Neural Networks》
C陷阱与缺陷 第6章 预处理器 6.1 不能忽视宏定义中的空格
【解决】关于 Unity Hub 获取许可证失败 或 无响应导致无法开发的问题
【Cloud Store Announcement】Notice of Help Center Update on July 30
基于stm32的shell实现
信息学奥赛一本通 1966:【14NOIP普及组】比例简化 | 洛谷 P2118 [NOIP2014 普及组] 比例简化
What is industrial radiography equipment?
leetcode-1319:连通网络的操作次数
Metaverse Web 3.0 和 DeFi大师班
高性能短链设计
Insert data into MySQL in C language
C陷阱与缺陷 第6章 预处理器 6.2 宏并不是函数
un7.30:Linux——如何在docker容器中显示MySQL的中文字符?
CMake library search function does not search LD_LIBRARY_PATH
LayaBox---TypeScript---类型兼容性
Ecplise执行C语言报错:cannot open output file xxx.exe: Permission denied
数据库系统原理与应用教程(067)—— MySQL 练习题:操作题 82-89(十一):数据的增、删、改操作