RammusPushIntentService.kt 3.6 KB
Newer Older
张国庆's avatar
张国庆 committed
1 2 3 4
package com.jarvanmo.rammus

import android.content.Context
import android.os.Handler
张国庆's avatar
张国庆 committed
5
import android.os.Looper
张国庆's avatar
张国庆 committed
6 7 8
import android.util.Log
import com.alibaba.sdk.android.push.AliyunMessageIntentService
import com.alibaba.sdk.android.push.notification.CPushMessage
张国庆's avatar
张国庆 committed
9
import com.blankj.utilcode.util.LogUtils
张国庆's avatar
张国庆 committed
10 11 12 13 14 15 16 17

/***
 * Created by mo on 2019-06-25
 * 冷风如刀,以大地为砧板,视众生为鱼肉。
 * 万里飞雪,将穹苍作烘炉,熔万物为白银。
 **/

class RammusPushIntentService : AliyunMessageIntentService() {
张国庆's avatar
张国庆 committed
18
    private val handler = Handler(Looper.getMainLooper())
张国庆's avatar
张国庆 committed
19 20

    override fun onNotificationRemoved(context: Context, messageId: String?) {
张国庆's avatar
张国庆 committed
21
        LogUtils.d("onNotificationRemoved messageId is $messageId")
张国庆's avatar
张国庆 committed
22 23 24 25 26 27 28

        handler.postDelayed( {
            RammusPushHandler.methodChannel?.invokeMethod("onNotificationRemoved", messageId)
        },1500)
    }

    override fun onNotification(context: Context, title: String?, summary: String?, extras: MutableMap<String, String>?) {
张国庆's avatar
张国庆 committed
29
        LogUtils.d("onNotification title is $title, summary is $summary, extras: $extras")
张国庆's avatar
张国庆 committed
30 31 32 33 34 35 36 37 38 39 40
        handler.postDelayed({

            RammusPushHandler.methodChannel?.invokeMethod("onNotification", mapOf(
                    "title" to title,
                    "summary" to summary,
                    "extras" to extras
            ))
        },1500)
    }

    override fun onMessage(context: Context, message: CPushMessage) {
张国庆's avatar
张国庆 committed
41
        LogUtils.d("onMessage title is ${message.title}, messageId is ${message.messageId}, content is ${message.content}")
张国庆's avatar
张国庆 committed
42 43 44 45 46 47 48 49 50 51 52 53 54
        handler.postDelayed( {
            RammusPushHandler.methodChannel?.invokeMethod("onMessageArrived", mapOf(
                    "appId" to message.appId,
                    "content" to message.content,
                    "messageId" to message.messageId,
                    "title" to message.title,
                    "traceInfo" to message.traceInfo
            ))
        },1500)
    }

    override fun onNotificationOpened(p0: Context?, title: String?, summary: String?, extras: String?) {

张国庆's avatar
张国庆 committed
55
        LogUtils.d("onNotificationOpened title is $title, summary is $summary, extras: $extras")
张国庆's avatar
张国庆 committed
56 57 58 59 60 61 62 63 64 65
        handler.postDelayed({
            RammusPushHandler.methodChannel?.invokeMethod("onNotificationOpened", mapOf(
                    "title" to title,
                    "summary" to summary,
                    "extras" to extras
            ))
        },1500)
    }

    override fun onNotificationReceivedInApp(p0: Context?, title: String?, summary: String?, extras: MutableMap<String, String>?, openType: Int, openActivity: String?, openUrl: String?) {
张国庆's avatar
张国庆 committed
66
        LogUtils.d("onNotificationReceivedInApp title is $title, summary is $summary, extras: $extras")
张国庆's avatar
张国庆 committed
67 68 69 70 71 72 73 74 75 76 77 78 79
        handler.postDelayed( {
            RammusPushHandler.methodChannel?.invokeMethod("onNotificationReceivedInApp", mapOf(
                    "title" to title,
                    "summary" to summary,
                    "extras" to extras,
                    "openType" to openType,
                    "openActivity" to openActivity,
                    "openUrl" to openUrl
            ))
        },1500)
    }

    override fun onNotificationClickedWithNoAction(context: Context, title: String?, summary: String?, extras: String?) {
张国庆's avatar
张国庆 committed
80
        LogUtils.d("onNotificationClickedWithNoAction title is $title, summary is $summary, extras: $extras")
张国庆's avatar
张国庆 committed
81 82 83 84 85 86 87 88 89
        handler.postDelayed(  {
            RammusPushHandler.methodChannel?.invokeMethod("onNotificationClickedWithNoAction", mapOf(
                    "title" to title,
                    "summary" to summary,
                    "extras" to extras
            ))
        }, 1500)
    }
}