Skip to content

Commit

Permalink
Define websocket foreground service type
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Nov 20, 2023
1 parent 0004b3c commit 8d28870
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

<application
android:name=".GotifyApplication"
Expand Down Expand Up @@ -73,7 +74,13 @@
android:exported="false"
android:theme="@style/AppTheme.Dialog" />

<service android:name=".service.WebSocketService" />
<service
android:name=".service.WebSocketService"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="explanation_for_special_use" />
</service>

<receiver android:name=".init.BootCompletedReceiver"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.Color
import android.net.ConnectivityManager
import android.net.Network
Expand Down Expand Up @@ -285,7 +286,15 @@ internal class WebSocketService : Service() {

notificationBuilder.setContentIntent(pendingIntent)
notificationBuilder.color = ContextCompat.getColor(applicationContext, R.color.colorPrimary)
startForeground(NotificationSupport.ID.FOREGROUND, notificationBuilder.build())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(
NotificationSupport.ID.FOREGROUND,
notificationBuilder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
)
} else {
startForeground(NotificationSupport.ID.FOREGROUND, notificationBuilder.build())
}
}

private fun showNotification(
Expand Down

0 comments on commit 8d28870

Please sign in to comment.