BootBroadcastReceiver.kt 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package fr.forum_thalie.tsumugi
  2. import android.content.BroadcastReceiver
  3. import android.content.Context
  4. import android.content.Intent
  5. import android.os.Build
  6. import android.util.Log
  7. import androidx.preference.PreferenceManager
  8. import fr.forum_thalie.tsumugi.alarm.RadioAlarm
  9. import fr.forum_thalie.tsumugi.playerstore.PlayerStore
  10. class BootBroadcastReceiver : BroadcastReceiver(){
  11. override fun onReceive(context: Context, arg1: Intent) {
  12. //[REMOVE LOG CALLS]//[REMOVE LOG CALLS]//[REMOVE LOG CALLS]Log.d(tag, "Broadcast Receiver received $arg1")
  13. // define preferenceStore for places of the program that needs to access Preferences without a context
  14. preferenceStore = PreferenceManager.getDefaultSharedPreferences(context)
  15. if (arg1.action == Intent.ACTION_BOOT_COMPLETED) {
  16. RadioAlarm.instance.setNextAlarm(context) // schedule next alarm
  17. }
  18. if (arg1.getStringExtra("action") == "$tag.${Actions.PLAY_OR_FALLBACK.name}" )
  19. {
  20. RadioAlarm.instance.setNextAlarm(context) // schedule next alarm
  21. if (!PlayerStore.instance.isInitialized)
  22. PlayerStore.instance.initApi()
  23. if (PlayerStore.instance.streamerName.value.isNullOrBlank())
  24. PlayerStore.instance.initPicture(context)
  25. val i = Intent(context, RadioService::class.java)
  26. i.putExtra("action", Actions.PLAY_OR_FALLBACK.name)
  27. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
  28. context.startForegroundService(i)
  29. else
  30. context.startService(i)
  31. }
  32. }
  33. }