feat: turned ReceiverService into foreground service
This commit is contained in:
parent
e954829595
commit
378e6f030d
2 changed files with 9 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
@ -33,7 +35,7 @@
|
||||||
<action android:name="com.example.broadcasts.action.CUSTOM_BROADCAST" />
|
<action android:name="com.example.broadcasts.action.CUSTOM_BROADCAST" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<service android:name=".ReceiverService" />
|
<service android:name=".ReceiverService" android:foregroundServiceType="specialUse"/>
|
||||||
<receiver android:name=".AlarmReceiver" />
|
<receiver android:name=".AlarmReceiver" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
|
@ -4,6 +4,7 @@ import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
|
||||||
class ReceiverService: Service() {
|
class ReceiverService: Service() {
|
||||||
|
|
||||||
|
@ -15,6 +16,11 @@ class ReceiverService: Service() {
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.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(
|
registerReceiver(
|
||||||
airplaneModeChangedReceiver,
|
airplaneModeChangedReceiver,
|
||||||
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)
|
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)
|
||||||
|
|
Loading…
Reference in a new issue