PushInitializer.kt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.narutohuo.xindazhou.push.startup
  2. import android.content.Context
  3. import androidx.startup.Initializer
  4. import com.narutohuo.xindazhou.core.log.ILog
  5. import com.narutohuo.xindazhou.push.factory.PushServiceFactory
  6. /**
  7. * 推送服务自动初始化器
  8. *
  9. * 使用 Jetpack Startup Library 实现自动初始化
  10. * 应用启动时自动执行,无需在 Application 中手动调用
  11. */
  12. class PushInitializer : Initializer<Unit> {
  13. companion object {
  14. private const val TAG = "PushInitializer"
  15. }
  16. override fun create(context: Context) {
  17. try {
  18. ILog.d(TAG, "开始自动初始化推送服务...")
  19. // 初始化推送服务
  20. PushServiceFactory.init(
  21. context = context.applicationContext,
  22. messageListener = null, // 默认无监听器,业务层可以后续设置
  23. notificationClickListener = null
  24. )
  25. ILog.d(TAG, "✅ 推送服务自动初始化完成")
  26. } catch (e: Exception) {
  27. ILog.e(TAG, "推送服务自动初始化失败", e)
  28. }
  29. }
  30. override fun dependencies(): List<Class<out Initializer<*>>> {
  31. // 无依赖
  32. return emptyList()
  33. }
  34. }