From 2aed021e08d56d433ccb59e2c086c585f800cf87 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sat, 11 May 2024 19:26:30 +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 #3929 --- app/src/main/java/io/legado/app/service/WebService.kt | 5 ++--- app/src/main/java/io/legado/app/utils/NetworkUtils.kt | 10 ++++------ 2 files changed, 6 insertions(+), 9 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 3193ff613..d703d947e 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -96,12 +96,11 @@ class WebService : BaseService() { if (addressList.any()) { notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) }) hostAddress = notificationList.first() - startForegroundNotification() } else { hostAddress = getString(R.string.network_connection_unavailable) notificationList.add(hostAddress) - startForegroundNotification() } + startForegroundNotification() postEvent(EventBus.WEB_SERVICE, hostAddress) } } @@ -184,6 +183,7 @@ class WebService : BaseService() { */ override fun startForegroundNotification() { val builder = NotificationCompat.Builder(this, AppConst.channelIdWeb) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setSmallIcon(R.drawable.ic_web_service_noti) .setOngoing(true) .setContentTitle(getString(R.string.web_service)) @@ -196,7 +196,6 @@ class WebService : BaseService() { getString(R.string.cancel), servicePendingIntent(IntentAction.stop) ) - builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() startForeground(NotificationId.WebService, notification) } diff --git a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt index a0e47b649..708559ff2 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -194,10 +194,10 @@ object NetworkUtils { enumeration = NetworkInterface.getNetworkInterfaces() } catch (e: SocketException) { e.printOnDebug() - return mutableListOf() + return emptyList() } - var fallbackAddress: MutableList = mutableListOf() + val addressList = mutableListOf() while (enumeration.hasMoreElements()) { val nif = enumeration.nextElement() @@ -205,13 +205,11 @@ object NetworkUtils { while (addresses.hasMoreElements()) { val address = addresses.nextElement() if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) { - if (nif.name?.startsWith("wlan") == true) { - fallbackAddress.add(address) - } + addressList.add(address) } } } - return fallbackAddress + return addressList } /**