Skip to content

Commit

Permalink
Set Android notification low importance
Browse files Browse the repository at this point in the history
  • Loading branch information
chen08209 committed May 1, 2024
1 parent 4d16820 commit e8feb7c
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class FlClashVpnService : VpnService() {

private val CHANNEL = "FlClash"

var fd: Int? = null;
var fd: Int? = null
private val notificationId: Int = 1

private val passList = listOf(
"*zhihu.com",
Expand Down Expand Up @@ -100,11 +101,12 @@ class FlClashVpnService : VpnService() {
fun startForeground(title: String, content: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_DEFAULT)
NotificationChannel(CHANNEL, "FlClash", NotificationManager.IMPORTANCE_LOW)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(channel)

val intent = Intent(this, MainActivity::class.java)

val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getActivity(
this,
Expand All @@ -120,7 +122,9 @@ class FlClashVpnService : VpnService() {
PendingIntent.FLAG_UPDATE_CURRENT
)
}

val icon = IconCompat.createWithResource(this, this.applicationInfo.icon)

val notification = with(NotificationCompat.Builder(this, CHANNEL)) {
setSmallIcon(icon)
setContentTitle(title)
Expand All @@ -132,12 +136,13 @@ class FlClashVpnService : VpnService() {
build()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(1, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
startForeground(notificationId, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
} else {
startForeground(1, notification)
startForeground(notificationId, notification)
}
}
}

private fun stopForeground() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
stopForeground(Service.STOP_FOREGROUND_REMOVE)
Expand Down

0 comments on commit e8feb7c

Please sign in to comment.