云巴第三方华为推送

华为手机 APP被杀也能收到消息

在华为官网获取相应的参数然后去云巴官网配置

华为参数

签名文件生成的sha256

jar包的获取

云巴的jar包

AndroidManifest.xml配置详情见demo

  • 权限


    
    
    
    
    
    
    
    
    

    
    
    
    


  
  • 参数配置
 
        
        
        

        
        
  • 其它


        
        
        
            
                
                
            
        

//自己定一个广播接收
        
            
                
                
                
                
                
                
            
        

        
            
                
                
            
        


        
            
                
                
                
                
                
                
                
                
                
                
            
        

        
            
                
                
            
        
        
看返回值
  • 混淆配置
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.hms.**{*;}
-keep class com.huawei.hms.support.api.**{*;}
-keep class com.xiaomi.**{*;}
-keep class org.apache.thrift.**{*;}
-dontwarn org.eclipse.paho.client.mqttv3.**
-keep class org.eclipse.paho.client.mqttv3.** { *; }
-keep class io.yunba.android.** { *; }
-dontnote io.yunba.android.**
-dontnote org.eclipse.paho.client.mqttv3.** 

参数配置正确在华为官网发消息就能收到了

发消息

重要的注意事项

  • 在华为官网SHA256一定要配置正确
  • 云巴官网一定要配置appid这些参数
  • app测试得时候一定要用正式版的签名文件,debug是不行的,这里容易忽略
  • 通过云巴api发消息notification_content这个json参数不能为空,为空收不到 , 我就被后端坑了
  • 华为移动服务更新一下


    最好配置一下签名文件,都引用正式签名文件
  • 去华为官网看看流程
    接入流程

  • 关于华为的自定义动作
    • 和我们使用Intent一样,显示意图隐式意图都可以,贴一下官方例子


      麻烦
腹肌撕裂者

上面配置完成就Ok了

自定义广播可以收到透传消息(可以不再通知栏显示,然后处理消息)

  • 这是在app内处理消息,被杀收不到
import com.huawei.hms.support.api.push.PushReceiver;

/**
 * Created by Administrator on 2018/3/30.
 */

public class MHwPushReceiver extends PushReceiver {
    @Override
    public void onToken(Context context, String token, Bundle extras) {
        System.out.println("push 收到消息token");
    }

    @Override
    public boolean onPushMsg(Context context, byte[] msg, Bundle bundle) {
        System.out.println("push onPushMsg    " + new String(msg));
        return true;//这里我是返回的true
    }


    public void onEvent(Context context, Event event, Bundle extras) {
        System.out.println("push onEvent");
    }

    @Override
    public void onPushState(Context context, boolean pushState) {
        System.out.println("push onPushState");
    }
}
  • 没去研究是哪一个action

            
                
                
                
                
                
            
        
  • 用于看日志的
    @Override
    public void onReceive(Context context, Intent intent) {

        //调试华为推送
        if (YunBaManager.MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) {

            String status = "Yunba - Connected";

            String topicORalias = intent.getStringExtra(YunBaManager.MQTT_TOPIC);
            String message = intent.getStringExtra(YunBaManager.MQTT_MSG);
            YunBaManager.report(context, "1001", topicORalias);

            StringBuilder msgsb = new StringBuilder();
            msgsb.append("receive message from server: ")
                    .append("topic/alias").append(" = ").append(topicORalias).append(" ,")
                    .append(YunBaManager.MQTT_MSG).append(" = ").append(message);
            System.out.println("pointercnPush MESSAGE_RECEIVED_ACTION 1    " + msgsb.toString());

        } else if (YunBaManager.PRESENCE_RECEIVED_ACTION.equals(intent.getAction())) {
            String status = "Yunba - Connected";

            String topic = intent.getStringExtra(YunBaManager.MQTT_TOPIC);
            String message = intent.getStringExtra(YunBaManager.MQTT_MSG);
            StringBuilder msgsb = new StringBuilder();
            msgsb.append("receive message from presence: ")
                    .append(YunBaManager.MQTT_TOPIC).append(" = ").append(topic).append(" ,")
                    .append(YunBaManager.MQTT_MSG).append(" = ").append(message);
            System.out.println("pointercnPush PRESENCE_RECEIVED_ACTION 2      " + msgsb.toString());
        } else if (YunBaManager.MESSAGE_CONNECTED_ACTION.equals(intent.getAction())) {
            String status = "Yunba - Connected";
            System.out.println("pointercnPush PRESENCE_RECEIVED_ACTION 3      connection success.");
        } else if (YunBaManager.MESSAGE_DISCONNECTED_ACTION.equals(intent.getAction())) {
            String status = "Yunba - DisConnected";
            System.out.println("pointercnPush MESSAGE_DISCONNECTED_ACTION 4      connection fail.");
        } else if (YunBaManager.MESSAGE_THIRD_PART_REGISTER_RESULT_ACTION.equals(intent.getAction())) {
            // 获取该广播属于哪个平台,YunbaManager.PLATFORM_HMS 即华为,YunBaManager.PLATFORM_XIAOMI 即小米
            int platform = intent.getIntExtra(YunBaManager.THIRD_PART_PLATFORM, 0);
            if (platform == YunBaManager.PLATFORM_HMS) {
                // 获取 token 数据
                String token = intent.getStringExtra(YunBaManager.THIRD_PART_REGISTER_RESULT_CODE);
                System.out.println("pointercnPush MESSAGE_THIRD_PART_REGISTER_RESULT_ACTION 5   " + token);
            } else if (platform == YunBaManager.PLATFORM_XIAOMI) {
                // 获取 token 数据
                String token = intent.getStringExtra(YunBaManager.THIRD_PART_REGISTER_RESULT_CODE);
                System.out.println("pointercnPush MESSAGE_THIRD_PART_REGISTER_RESULT_ACTION 5   " + token);
            }
        }
    }

你可能感兴趣的:(云巴第三方华为推送)