当前位置:网站首页>【开发者必看】【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
边栏推荐
- Vulkan与OpenGL对比——Vulkan的全新渲染架构
- Mathematical Principles of Graph Convolutional Neural Networks——A Preliminary Study on Spectral Graph Theory and Fourier Transform
- [HarekazeCTF2019] Avatar Uploader 1
- Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)
- Microsoft Office 2019 software download and installation detailed tutorial!
- SQL行列转换
- What ARC does at compile time and runtime
- Ecplise执行C语言报错:cannot open output file xxx.exe: Permission denied
- Web 3.0入门教程
- reporter undercover
猜你喜欢

2022鹏城杯web

升级 MDK 5.37 后的问题处理: AC6编译选项, printf, 重启失效等

Hangzhou electric school game 2 1001 2022 Static Query on Tree (Tree + hash table difference chain subdivision

leetcode-547:省份数量

Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法

公司部门来了个00后测试卷王之王,老油条表示真干不过,已经...

莫队--优雅的暴力

基于MATLAB的电力系统短路故障分析与仿真

un7.30:Linux——如何在docker容器中显示MySQL的中文字符?

Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)
随机推荐
What are the applications of X-rays?
Moralis去中心化Web3应用开发教程
游戏化产品搭建思路的拆解与探究
C陷阱与缺陷 第6章 预处理器
基于stm32的shell实现
[OC学习笔记]属性关键字
【网络工程】A、B、C、D、E类IP地址划分依据和特殊的IP地址
知识蒸馏4:准备数据集并修改网络配置
Hangzhou electric school game 2 1001 2022 Static Query on Tree (Tree + hash table difference chain subdivision
shell快速移植
Promise entry to proficient (1.5w word detailed explanation)
基于模糊PID的液压舵机伺服系统
C陷阱与缺陷 第7章 可移植性缺陷 7.5 移位运算符
宽带射频放大器OA4SMM4(1)
Error occurred while trying to proxy request The project suddenly can't get up
知识蒸馏2:目标检测中的知识蒸馏
记者卧底
数据库系统原理与应用教程(068)—— MySQL 练习题:操作题 90-94(十二):DML 语句练习
PLSQL Developer安装和配置
BI报表与数据开发