当前位置:网站首页>【开发者必看】【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
边栏推荐
- [HarekazeCTF2019] Avatar Uploader 1
- Promise entry to proficient (1.5w word detailed explanation)
- Error occurred while trying to proxy request项目突然起不来了
- LayaBox---TypeScript---枚举
- 开源盛宴ApacheCon Asia 2022即将开幕,精彩不容错过!
- Excel导入和导出
- Hangzhou electric school game 2 1001 2022 Static Query on Tree (Tree + hash table difference chain subdivision
- linux 下MySQL本地安装mysql - u root - p 无法登入
- 测试行业干了5年,从只会点点点到了现在的测试开发,总算是证明了自己
- 快使用flyway管理sql脚本吧~
猜你喜欢
随机推荐
linux 下MySQL本地安装mysql - u root - p 无法登入
Promise入门到精通(1.5w字详解)
Test the.net text to Speech module System. Researched
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
JMeter笔记3 | JMeter安装和环境说明
知识蒸馏4:准备数据集并修改网络配置
Analysis and Simulation of Short Circuit Fault in Power System Based on MATLAB
LeetCode 952. 按公因数计算最大组件大小
今年这情况。。真心推荐专科的工程师升个本!
基于MATLAB的电力系统短路故障分析与仿真
Ecplise执行C语言报错:cannot open output file xxx.exe: Permission denied
What ARC does at compile time and runtime
JMeter Notes 4 | JMeter Interface Introduction
什么是无损检测设备?
What are the applications of X-rays?
Error occurred while trying to proxy request项目突然起不来了
FastJson反序列化漏洞(复现)
Logback的使用
fast shell porting
测试行业干了5年,从只会点点点到了现在的测试开发,总算是证明了自己






![Valid bracketed strings [greedy exercise]](/img/1c/5cefb53bc4aba54dd79b0cc9b09b0d.png)


