Skip to content

Commit

Permalink
Declare foreground service type
Browse files Browse the repository at this point in the history
API level 34 requirement
  • Loading branch information
erdemyerebasmaz committed Dec 28, 2023
1 parent c5d1e7e commit 39189b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<service
android:name=".BreezForegroundService"
android:foregroundServiceType="shortService"
android:exported="false"
android:stopWithTask="false">
</service>
Expand Down
16 changes: 13 additions & 3 deletions android/app/src/main/java/com/cBreez/client/BreezSdkWorker.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.cBreez.client

import android.content.Context
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
import android.os.Build
import androidx.work.ForegroundInfo
import androidx.work.Worker
import androidx.work.WorkerParameters
Expand Down Expand Up @@ -37,9 +39,17 @@ open class BreezSdkWorker(appContext: Context, workerParams: WorkerParameters) :
}

override fun getForegroundInfo(): ForegroundInfo {
return ForegroundInfo(
NOTIFICATION_ID_FOREGROUND_SERVICE, notifyForegroundService(applicationContext)
)
val notification = notifyForegroundService(applicationContext)
val foregroundInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(
NOTIFICATION_ID_FOREGROUND_SERVICE,
notification,
FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
)
} else {
ForegroundInfo(NOTIFICATION_ID_FOREGROUND_SERVICE, notification)
}
return foregroundInfo
}

override fun doWork(): Result {
Expand Down

0 comments on commit 39189b1

Please sign in to comment.