1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cn.flightfeather.thirdappmodule.util.push
 
import android.content.Context
import android.util.Log
 
import com.alibaba.sdk.android.push.AliyunMessageIntentService
import com.alibaba.sdk.android.push.notification.CPushMessage
 
/**
 * 为避免推送广播被系统拦截的小概率事件,我们推荐用户通过IntentService处理消息互调,接入步骤:
 * 详细用户可参考:https://help.aliyun.com/document_detail/30066.html#h2-2-messagereceiver-aliyunmessageintentservice
 */
 
class MyMessageIntentService : AliyunMessageIntentService() {
 
    companion object {
        private const val REC_TAG = "MyMessageIntentService"
    }
 
    /**
     * 推送通知的回调方法
     * @param context
     * @param title
     * @param summary
     * @param extraMap
     */
    override fun onNotification(context: Context, title: String, summary: String, extraMap: Map<String, String>) {
        Log.i(REC_TAG, "收到一条推送通知 : $title, summary:$summary")
    }
 
    /**
     * 推送消息的回调方法
     * @param context
     * @param cPushMessage
     */
    override fun onMessage(context: Context, cPushMessage: CPushMessage) {
        Log.i(REC_TAG, "收到一条推送消息 : " + cPushMessage.title + ", content:" + cPushMessage.content)
    }
 
    /**
     * 从通知栏打开通知的扩展处理
     * @param context
     * @param title
     * @param summary
     * @param extraMap
     */
    override fun onNotificationOpened(context: Context, title: String, summary: String, extraMap: String) {
        Log.i(REC_TAG, "onNotificationOpened :  : $title : $summary : $extraMap")
 
    }
 
    /**
     * 无动作通知点击回调。当在后台或阿里云控制台指定的通知动作为无逻辑跳转时,通知点击回调为onNotificationClickedWithNoAction而不是onNotificationOpened
     * @param context
     * @param title
     * @param summary
     * @param extraMap
     */
    override fun onNotificationClickedWithNoAction(context: Context, title: String, summary: String, extraMap: String) {
        Log.i(REC_TAG, "onNotificationClickedWithNoAction :  : $title : $summary : $extraMap")
    }
 
    /**
     * 通知删除回调
     * @param context
     * @param messageId
     */
    override fun onNotificationRemoved(context: Context, messageId: String) {
        Log.i(REC_TAG, "onNotificationRemoved : $messageId")
    }
 
    /**
     * 应用处于前台时通知到达回调。注意:该方法仅对自定义样式通知有效,相关详情请参考https://help.aliyun.com/document_detail/30066.html#h3-3-4-basiccustompushnotification-api
     * @param context
     * @param title
     * @param summary
     * @param extraMap
     * @param openType
     * @param openActivity
     * @param openUrl
     */
    override fun onNotificationReceivedInApp(
        context: Context,
        title: String,
        summary: String,
        extraMap: Map<String, String>,
        openType: Int,
        openActivity: String,
        openUrl: String
    ) {
        Log.i(
            REC_TAG,
            "onNotificationReceivedInApp :  : $title : $summary  $extraMap : $openType : $openActivity : $openUrl"
        )
    }
}