From c53e7897624a14a374b127bc2ccd10abcde3b049 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:04:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/WebService.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index d703d947e..b34c58cc8 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -7,7 +7,6 @@ import android.net.wifi.WifiManager import android.os.Build import android.os.PowerManager import androidx.core.app.NotificationCompat -import androidx.core.content.ContextCompat import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst @@ -23,6 +22,7 @@ import io.legado.app.utils.postEvent import io.legado.app.utils.printOnDebug import io.legado.app.utils.sendToClip import io.legado.app.utils.servicePendingIntent +import io.legado.app.utils.startForegroundServiceCompat import io.legado.app.utils.startService import io.legado.app.utils.stopService import io.legado.app.utils.toastOnUi @@ -45,7 +45,7 @@ class WebService : BaseService() { fun startForeground(context: Context) { val intent = Intent(context, WebService::class.java) - ContextCompat.startForegroundService(context, intent) + context.startForegroundServiceCompat(intent) } fun stop(context: Context) { @@ -94,7 +94,13 @@ class WebService : BaseService() { val addressList = NetworkUtils.getLocalIPAddress() notificationList.clear() if (addressList.any()) { - notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }) + notificationList.addAll(addressList.map { address -> + getString( + R.string.http_ip, + address.hostAddress, + getPort() + ) + }) hostAddress = notificationList.first() } else { hostAddress = getString(R.string.network_connection_unavailable) @@ -154,7 +160,13 @@ class WebService : BaseService() { httpServer?.start() webSocketServer?.start(1000 * 30) // 通信超时设置 notificationList.clear() - notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }) + notificationList.addAll(addressList.map { address -> + getString( + R.string.http_ip, + address.hostAddress, + getPort() + ) + }) hostAddress = notificationList.first() isRun = true postEvent(EventBus.WEB_SERVICE, hostAddress)