X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Freceivers%2FOnBootCompletedReceiver.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Freceivers%2FOnBootCompletedReceiver.kt;h=54e23e937281a57004921a4ccbd98fb4745e1162;hp=0000000000000000000000000000000000000000;hb=976d7da4c16f9ddc87f0cd7c67cd2eefc9f260b1;hpb=70a8bdb781941d9f433b18a91befe03137d65a6f diff --git a/app/src/main/java/com/stoutner/privacycell/receivers/OnBootCompletedReceiver.kt b/app/src/main/java/com/stoutner/privacycell/receivers/OnBootCompletedReceiver.kt new file mode 100644 index 0000000..54e23e9 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacycell/receivers/OnBootCompletedReceiver.kt @@ -0,0 +1,45 @@ +/* + * Copyright © 2021 Soren Stoutner . + * + * This file is part of Privacy Cell . + * + * Privacy Cell is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Cell is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Cell. If not, see . + */ + +package com.stoutner.privacycell.receivers + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import androidx.preference.PreferenceManager +import com.stoutner.privacycell.R +import com.stoutner.privacycell.services.RealtimeMonitoringService + +class OnBootCompletedReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + // Check to make sure the system ACTION_BOOT_COMPLETED initiated the receiver. + if (intent.action == Intent.ACTION_BOOT_COMPLETED) { + // Get a handle for the shared preferences. + val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + + // Get the realtime monitoring preference. + val realtimeMonitoring = sharedPreferences.getBoolean(context.getString(R.string.realtime_monitoring_key), false) + + // Start the realtime monitoring service if it is enabled. + if (realtimeMonitoring) { + context.startForegroundService(Intent(context, RealtimeMonitoringService::class.java)) + } + } + } +} \ No newline at end of file