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, 用网页测试推送时,一定要全部写

  • 相关阅读:
    zoj 4120Tokens on the Segments(优先队列+贪心)
    hdu1710 Binary Tree Traversals(二叉树)
    poj3494Largest Submatrix of All 1’s
    poj 2559Largest Rectangle in a Histogram(单调栈简单模板题)
    poj 2492 A Bug's Life(种类并查集)
    差分约束 + spfa + 最长路 [NOI1999] 01串
    Codeforces Round #599 D Yet Another Monster Killing Problem
    CF 1249D1
    [Gym-102346A] 偷偷偷 并查集处理图(坐标)
    [Gym-102346M] 二分答案
  • 原文地址:https://www.cnblogs.com/dzqdzq/p/12788618.html
Copyright © 2011-2022 走看看