ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【开发者必看】【push kit】推送服务典型问题合集3

2022-07-30 08:01:14  阅读:152  来源: 互联网

标签:name 必看 bundle kit Push Token 应用 push notificationChannel


​ 

【问题描述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

标签:name,必看,bundle,kit,Push,Token,应用,push,notificationChannel
来源: https://www.cnblogs.com/developer-huawei/p/16534244.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有