|
|
|
@ -2,6 +2,7 @@ package io.legado.app.service |
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Build |
|
|
|
|
import androidx.core.app.NotificationCompat |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseService |
|
|
|
@ -40,7 +41,7 @@ class WebService : BaseService() { |
|
|
|
|
isRun = true |
|
|
|
|
notificationContent = getString(R.string.service_starting) |
|
|
|
|
upNotification() |
|
|
|
|
WebTileService.setState(this, true) |
|
|
|
|
upTile(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
@ -53,7 +54,7 @@ class WebService : BaseService() { |
|
|
|
|
webSocketServer?.stop() |
|
|
|
|
} |
|
|
|
|
postEvent(EventBus.WEB_SERVICE, "") |
|
|
|
|
WebTileService.setState(this, false) |
|
|
|
|
upTile(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { |
|
|
|
@ -123,4 +124,16 @@ class WebService : BaseService() { |
|
|
|
|
val notification = builder.build() |
|
|
|
|
startForeground(AppConst.notificationIdWeb, notification) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upTile(active: Boolean) { |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
|
|
|
|
startService<WebTileService> { |
|
|
|
|
action = if (active) { |
|
|
|
|
IntentAction.start |
|
|
|
|
} else { |
|
|
|
|
IntentAction.stop |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|