Created
June 30, 2019 11:32
-
-
Save robertohuertasm/754c97179000e584bb9f5d517539922a to your computer and use it in GitHub Desktop.
foreground_services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StartReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
if (intent.action == Intent.ACTION_BOOT_COMPLETED && getServiceState(context) == ServiceState.STARTED) { | |
Intent(context, EndlessService::class.java).also { | |
it.action = Actions.START.name | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
log("Starting the service in >=26 Mode from a BroadcastReceiver") | |
context.startForegroundService(it) | |
return | |
} | |
log("Starting the service in < 26 Mode from a BroadcastReceiver") | |
context.startService(it) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment