package com.parentalmonitor.child.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.os.Build import android.util.Log import com.parentalmonitor.child.services.MonitoringService class BootReceiver : BroadcastReceiver() { companion object { const val TAG = "BootReceiver" } override fun onReceive(context: Context, intent: Intent) { val action = intent.action if (action == Intent.ACTION_BOOT_COMPLETED || action == "android.intent.action.QUICKBOOT_POWERON" || action == "com.htc.intent.action.QUICKBOOT_POWERON") { Log.d(TAG, "Boot completed, starting monitoring service") // Check if device is linked val prefs = context.getSharedPreferences("parental_monitor", Context.MODE_PRIVATE) val deviceId = prefs.getInt("device_id", -1) if (deviceId > 0) { val serviceIntent = Intent(context, MonitoringService::class.java) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { context.startForegroundService(serviceIntent) } else { context.startService(serviceIntent) } Log.d(TAG, "Monitoring service started after boot") } else { Log.d(TAG, "Device not linked, skipping service start") } } } }