package cn.flightfeather.thirdappmodule.util.push
|
|
import android.content.Context
|
import android.util.Log
|
import com.alibaba.sdk.android.push.CloudPushService
|
import com.alibaba.sdk.android.push.CommonCallback
|
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
|
|
/**
|
* 移动推送服务配置类
|
* @author riku
|
* Date: 2019/12/26
|
*/
|
class PushService {
|
companion object {
|
const val TAG = "PushService"
|
|
private var mPushService: CloudPushService? = null
|
|
/**
|
* 初始化云推送通道
|
* @param applicationContext
|
*/
|
fun init(applicationContext: Context) {
|
PushServiceFactory.init(applicationContext)
|
mPushService = PushServiceFactory.getCloudPushService()
|
mPushService?.register(applicationContext, object : CommonCallback {
|
override fun onSuccess(response: String) {
|
Log.d(TAG, "init cloudChannel success")
|
Log.d(TAG, response)
|
}
|
|
override fun onFailed(errorCode: String, errorMessage: String) {
|
Log.d(TAG, "init cloudChannel failed -- errorCode:$errorCode -- errorMessage:$errorMessage")
|
}
|
})
|
}
|
|
fun bindAccount(account: String, s: () -> Unit) {
|
mPushService?.bindAccount(account, object : CommonCallback {
|
override fun onSuccess(p0: String?) {
|
Log.d(TAG, "bind account $account success")
|
s()
|
}
|
|
override fun onFailed(p0: String?, p1: String?) {
|
|
}
|
})
|
}
|
|
fun unBindAccount(s: () -> Unit) {
|
mPushService?.unbindAccount(object : CommonCallback {
|
override fun onSuccess(p0: String?) {
|
Log.d(TAG, "unbind account success")
|
s()
|
}
|
|
override fun onFailed(p0: String?, p1: String?) {
|
|
}
|
})
|
}
|
}
|
}
|