#3929
This commit is contained in:
Horis 2024-05-11 19:26:30 +08:00
parent 06d486c96c
commit 2aed021e08
2 changed files with 6 additions and 9 deletions

View File

@ -96,12 +96,11 @@ class WebService : BaseService() {
if (addressList.any()) { 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() hostAddress = notificationList.first()
startForegroundNotification()
} else { } else {
hostAddress = getString(R.string.network_connection_unavailable) hostAddress = getString(R.string.network_connection_unavailable)
notificationList.add(hostAddress) notificationList.add(hostAddress)
startForegroundNotification()
} }
startForegroundNotification()
postEvent(EventBus.WEB_SERVICE, hostAddress) postEvent(EventBus.WEB_SERVICE, hostAddress)
} }
} }
@ -184,6 +183,7 @@ class WebService : BaseService() {
*/ */
override fun startForegroundNotification() { override fun startForegroundNotification() {
val builder = NotificationCompat.Builder(this, AppConst.channelIdWeb) val builder = NotificationCompat.Builder(this, AppConst.channelIdWeb)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_web_service_noti) .setSmallIcon(R.drawable.ic_web_service_noti)
.setOngoing(true) .setOngoing(true)
.setContentTitle(getString(R.string.web_service)) .setContentTitle(getString(R.string.web_service))
@ -196,7 +196,6 @@ class WebService : BaseService() {
getString(R.string.cancel), getString(R.string.cancel),
servicePendingIntent<WebService>(IntentAction.stop) servicePendingIntent<WebService>(IntentAction.stop)
) )
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build() val notification = builder.build()
startForeground(NotificationId.WebService, notification) startForeground(NotificationId.WebService, notification)
} }

View File

@ -194,10 +194,10 @@ object NetworkUtils {
enumeration = NetworkInterface.getNetworkInterfaces() enumeration = NetworkInterface.getNetworkInterfaces()
} catch (e: SocketException) { } catch (e: SocketException) {
e.printOnDebug() e.printOnDebug()
return mutableListOf() return emptyList()
} }
var fallbackAddress: MutableList<InetAddress> = mutableListOf() val addressList = mutableListOf<InetAddress>()
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
val nif = enumeration.nextElement() val nif = enumeration.nextElement()
@ -205,13 +205,11 @@ object NetworkUtils {
while (addresses.hasMoreElements()) { while (addresses.hasMoreElements()) {
val address = addresses.nextElement() val address = addresses.nextElement()
if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) { if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) {
if (nif.name?.startsWith("wlan") == true) { addressList.add(address)
fallbackAddress.add(address)
}
} }
} }
} }
return fallbackAddress return addressList
} }
/** /**