diff options
Diffstat (limited to 'app/src/main/java/sh/lajo/buddy/BootReceiver.kt')
| -rw-r--r-- | app/src/main/java/sh/lajo/buddy/BootReceiver.kt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/src/main/java/sh/lajo/buddy/BootReceiver.kt b/app/src/main/java/sh/lajo/buddy/BootReceiver.kt new file mode 100644 index 0000000..6f0867c --- /dev/null +++ b/app/src/main/java/sh/lajo/buddy/BootReceiver.kt @@ -0,0 +1,23 @@ +package sh.lajo.buddy + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.os.Build + +class BootReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + if (intent.action == Intent.ACTION_BOOT_COMPLETED) { + val prefs = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE) + if (!prefs.getBoolean("onboardingFinished", false)) return + + val serviceIntent = Intent(context, WebSocketService::class.java) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(serviceIntent) + } else { + context.startService(serviceIntent) + } + } + } +} |