Skip to content

Commit 8d28870

Browse files
committed
Define websocket foreground service type
1 parent 0004b3c commit 8d28870

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
1111
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1212
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
13+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
1314

1415
<application
1516
android:name=".GotifyApplication"
@@ -73,7 +74,13 @@
7374
android:exported="false"
7475
android:theme="@style/AppTheme.Dialog" />
7576

76-
<service android:name=".service.WebSocketService" />
77+
<service
78+
android:name=".service.WebSocketService"
79+
android:foregroundServiceType="specialUse">
80+
<property
81+
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
82+
android:value="explanation_for_special_use" />
83+
</service>
7784

7885
<receiver android:name=".init.BootCompletedReceiver"
7986
android:exported="true">

app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.app.NotificationManager
66
import android.app.PendingIntent
77
import android.app.Service
88
import android.content.Intent
9+
import android.content.pm.ServiceInfo
910
import android.graphics.Color
1011
import android.net.ConnectivityManager
1112
import android.net.Network
@@ -285,7 +286,15 @@ internal class WebSocketService : Service() {
285286

286287
notificationBuilder.setContentIntent(pendingIntent)
287288
notificationBuilder.color = ContextCompat.getColor(applicationContext, R.color.colorPrimary)
288-
startForeground(NotificationSupport.ID.FOREGROUND, notificationBuilder.build())
289+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
290+
startForeground(
291+
NotificationSupport.ID.FOREGROUND,
292+
notificationBuilder.build(),
293+
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
294+
)
295+
} else {
296+
startForeground(NotificationSupport.ID.FOREGROUND, notificationBuilder.build())
297+
}
289298
}
290299

291300
private fun showNotification(

0 commit comments

Comments
 (0)