riku
2025-10-31 1897c4ad5fa73b3f0a36e1aa0e1e9000302a6ace
app/src/main/java/cn/flightfeather/thirdappmodule/util/push/PushService.kt
@@ -2,9 +2,9 @@
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
//import com.alibaba.sdk.android.push.CloudPushService
//import com.alibaba.sdk.android.push.CommonCallback
//import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
/**
 * 移动推送服务配置类
@@ -12,54 +12,54 @@
 * 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?) {
                }
            })
        }
    }
//    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?) {
//
//                }
//            })
//        }
//    }
}