mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
新增:网络状态监控通知增加IPv6获取(排除本地地址) #321
This commit is contained in:
parent
ec7801a015
commit
0767082ee6
@ -93,7 +93,7 @@ class NetworkStateService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取IP地址
|
//获取IP地址
|
||||||
val ipList = CommonUtils.getIPAddresses()
|
val ipList = CommonUtils.getIPAddresses().filter { !isLocalAddress(it) }
|
||||||
if (ServiceUtils.isServiceRunning("com.idormy.sms.forwarder.service.HttpService")) {
|
if (ServiceUtils.isServiceRunning("com.idormy.sms.forwarder.service.HttpService")) {
|
||||||
ipList.forEach() {
|
ipList.forEach() {
|
||||||
msg.append(getString(R.string.host_address)).append(": ").append(it).append("\n")
|
msg.append(getString(R.string.host_address)).append(": ").append(it).append("\n")
|
||||||
@ -126,6 +126,11 @@ class NetworkStateService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//检查IP地址是否为本地地址
|
||||||
|
private fun isLocalAddress(ip: String): Boolean {
|
||||||
|
return ip == "127.0.0.1" || ip == "::1" || ip.startsWith("fe80:") || ip.startsWith("fec0:")
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "NetworkStateReceiver"
|
private const val TAG = "NetworkStateReceiver"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user