BootCompletedReceiver.kt raw

   1  package io.github.domi04151309.alwayson.receivers
   2  
   3  import android.content.BroadcastReceiver
   4  import android.content.Context
   5  import android.content.Intent
   6  import androidx.core.content.ContextCompat
   7  import io.github.domi04151309.alwayson.services.ForegroundService
   8  
   9  class BootCompletedReceiver : BroadcastReceiver() {
  10      override fun onReceive(
  11          context: Context,
  12          intent: Intent,
  13      ) {
  14          if (
  15              intent.action == Intent.ACTION_BOOT_COMPLETED ||
  16              intent.action == Intent.ACTION_MY_PACKAGE_REPLACED
  17          ) {
  18              ContextCompat.startForegroundService(
  19                  context,
  20                  Intent(context, ForegroundService::class.java),
  21              )
  22          }
  23      }
  24  }
  25