友盟集成厂商通道推送部分坑记录

1,924 阅读1分钟
  1. 华为的厂商通道是要验证签名的  验证签名  验证签名
  2. 适配8.0版本之后的通知是要设置ChannelName,使用友盟的有2个办法:

    方法一:使用友盟提供的方法
    PushAgent.getInstance(context).setNotificationChannelName("推送通知");
    
    方法二:自定义通知栏样式
    UmengMessageHandler handler= new UmengMessageHandler() {  /**     
      * 自定义通知栏样式的回调方法     
      */    
    @Override    
    public Notification getNotification(Context context, UMessage msg) {        
        switch (msg.builder_id) {      
            case 1:      
               //在这里自定义通知栏的地方设置ChannelName
                NotificationChannel channel = null;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { 
                    //channel_id  自定义个一个id   
                    channel = new NotificationChannel("channel_id", "推送通知", NotificationManager.IMPORTANCE_DEFAULT);    
                    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);    
                    if (manager != null) {        
                        manager.createNotificationChannel(channel);    
                    }
                }
                Notification.Builder builder = new Notification.Builder(context);
                xxxxxxxxxxxxxxx省略自定义通知栏的代码
                return builder.build();
            default:
                //默认为0,若填写的builder_id并不存在,也使用默认。            
          return super.getNotification(context, msg);    }    
     }
    };
    PushAgent.getInstance(context).setMessageHandler(handler);
    
        注意:如果使用默认的通知栏样式 只能通过方法一来做 所以稳妥点可以不管是否是自定义通知栏样式
    都将方法一加上 如果使用自定义样式的话 记得设置ChannelName
  3.  oppo、vivo手机默认通知权限关闭的 需要引导用户打开     

未完待续....