| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.narutohuo.xindazhou.push.startup
- import android.content.Context
- import androidx.startup.Initializer
- import com.narutohuo.xindazhou.core.log.ILog
- import com.narutohuo.xindazhou.push.factory.PushServiceFactory
- /**
- * 推送服务自动初始化器
- *
- * 使用 Jetpack Startup Library 实现自动初始化
- * 应用启动时自动执行,无需在 Application 中手动调用
- */
- class PushInitializer : Initializer<Unit> {
-
- companion object {
- private const val TAG = "PushInitializer"
- }
-
- override fun create(context: Context) {
- try {
- ILog.d(TAG, "开始自动初始化推送服务...")
-
- // 初始化推送服务
- PushServiceFactory.init(
- context = context.applicationContext,
- messageListener = null, // 默认无监听器,业务层可以后续设置
- notificationClickListener = null
- )
-
- ILog.d(TAG, "✅ 推送服务自动初始化完成")
- } catch (e: Exception) {
- ILog.e(TAG, "推送服务自动初始化失败", e)
- }
- }
-
- override fun dependencies(): List<Class<out Initializer<*>>> {
- // 无依赖
- return emptyList()
- }
- }
|