zoukankan      html  css  js  c++  java
  • 小记接入阿里云推送

    搞这个sdk居然花了3天时间. 无语.....

    有几个注意的点,免得以后接入的时候再次躺坑

    1, 一定要接入厂商通道,

    2, 一定要实现MainApplication

    3, 一定要在MainApplication这样初始化,

    public void onCreate() {
            super.onCreate();
            initCloudChannel(this);
            MiPushRegister.register(this, "x x x x xxxxx", "5721838183847");
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                // 通知渠道的id
                String id = "2";
                String name = "比赛";
                String description = "开赛提醒";
                int importance = NotificationManager.IMPORTANCE_HIGH;
                NotificationChannel mChannel = new NotificationChannel(id, name, importance);
                // 配置通知渠道的属性
                mChannel.setDescription(description);
                // 设置通知出现时的闪灯(如果 android 设备支持的话)
                mChannel.enableLights(true);
                mChannel.setLightColor(Color.RED);
                // 设置通知出现时的震动(如果 android 设备支持的话)
                mChannel.enableVibration(true);
                mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                //最后在notificationmanager中创建该通知渠道
                mNotificationManager.createNotificationChannel(mChannel);
            }
        }
    

     4, 一定要实现: PopupPushActivity, MyMessageReceiver

    package com.bjcardsports.halo.aliyun;
    
    import android.os.Bundle;
    import android.util.Log;
    
    import com.alibaba.sdk.android.push.AndroidPopupActivity;
    
    import java.util.Map;
    
    public class PopupPushActivity extends AndroidPopupActivity {
        static final String TAG = "PopupPushActivity";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    
        @Override
        protected void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
            Log.d("OnMiPushSysNoticeOpened", "title: " + title + ", content: " + summary + ", extMap: " + extMap);
        }
    }
    
    package com.bjcardsports.halo.aliyun;
    
    import android.content.Context;
    import android.util.Log;
    
    import com.alibaba.sdk.android.push.MessageReceiver;
    import com.alibaba.sdk.android.push.notification.CPushMessage;
    
    import java.util.Map;
    
    public class MyMessageReceiver extends MessageReceiver {
        // 消息接收部分的LOG_TAG
        public static final String REC_TAG = "receiver";
        @Override
        public void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
            // TODO 处理推送通知
            Log.e("MyMessageReceiver", "Receive notification, title: " + title + ", summary: " + summary + ", extraMap: " + extraMap);
        }
        @Override
        public void onMessage(Context context, CPushMessage cPushMessage) {
            Log.e("MyMessageReceiver", "onMessage, messageId: " + cPushMessage.getMessageId() + ", title: " + cPushMessage.getTitle() + ", content:" + cPushMessage.getContent());
        }
        @Override
        public void onNotificationOpened(Context context, String title, String summary, String extraMap) {
            Log.e("MyMessageReceiver", "onNotificationOpened, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);
        }
        @Override
        protected void onNotificationClickedWithNoAction(Context context, String title, String summary, String extraMap) {
            Log.e("MyMessageReceiver", "onNotificationClickedWithNoAction, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap);
        }
        @Override
        protected void onNotificationReceivedInApp(Context context, String title, String summary, Map<String, String> extraMap, int openType, String openActivity, String openUrl) {
            Log.e("MyMessageReceiver", "onNotificationReceivedInApp, title: " + title + ", summary: " + summary + ", extraMap:" + extraMap + ", openType:" + openType + ", openActivity:" + openActivity + ", openUrl:" + openUrl);
        }
        @Override
        protected void onNotificationRemoved(Context context, String messageId) {
            Log.e("MyMessageReceiver", "onNotificationRemoved");
        }
    }
    

     5, 后台一定要添加通道:

    6, 用网页测试推送时,一定要全部写

  • 相关阅读:
    IntelliJ IDEA 添加本地xsd文件
    Dubbox离线约束地址
    IDEA发布运行web项目(曾经遇到的项目启动报404)
    项目导入时报错:The import javax.servlet.http.HttpServletRequest cannot be resolved
    IDEA使用maven中tomcat插件来启动服务器配置
    NetCore实践篇:分布式监控客户端ZipkinTracer从入门到放弃之路
    .Net外包篇:我是怎么看待外包的(二)
    .Net外包篇:我是如何看待外包的
    .Net架构篇:思考如何设计一款实用的分布式监控系统?
    分布式Redis缓存串讲(一)
  • 原文地址:https://www.cnblogs.com/dzqdzq/p/12788618.html
Copyright © 2011-2022 走看看