From 378e6f030db3db3dcfd197f46f369a6856b9fee0 Mon Sep 17 00:00:00 2001 From: tilera Date: Mon, 1 Jul 2024 19:16:49 +0200 Subject: [PATCH] feat: turned ReceiverService into foreground service --- app/src/main/AndroidManifest.xml | 4 +++- app/src/main/java/com/example/broadcasts/ReceiverService.kt | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ba89d15..e619b30 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + - + \ No newline at end of file diff --git a/app/src/main/java/com/example/broadcasts/ReceiverService.kt b/app/src/main/java/com/example/broadcasts/ReceiverService.kt index da75a09..55822ca 100644 --- a/app/src/main/java/com/example/broadcasts/ReceiverService.kt +++ b/app/src/main/java/com/example/broadcasts/ReceiverService.kt @@ -4,6 +4,7 @@ import android.app.Service import android.content.Intent import android.content.IntentFilter import android.os.IBinder +import androidx.core.app.NotificationCompat class ReceiverService: Service() { @@ -15,6 +16,11 @@ class ReceiverService: Service() { override fun onCreate() { super.onCreate() + val notification = NotificationCompat.Builder(this, "default_notifications") + .setSmallIcon(R.drawable.ic_launcher_background) + .setContentTitle("Listening for Airplanemode change") + .build() + startForeground(2, notification) registerReceiver( airplaneModeChangedReceiver, IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)