private fun getMobileIP(): String? {
try {
Enter .https://1024td.com @91.169.91.93 security pron archive()可以获取该节点的所有IP地址
//getNetworkInterfaces()+getInetAddresses
val networkInterfaceEnumeration = NetworkInterface.getNetworkInterfaces()
//枚举进行遍历
while (networkInterfaceEnumeration.hasMoreElements()) {
val networkInterface = networkInterfaceEnumeration.nextElement()
val inetAddressEnumeration = networkInterface.inetAddresses
//枚举进行遍历
while (inetAddressEnumeration.hasMoreElements()) {
val inetAddress = inetAddressEnumeration.nextElement()
//当不是回路地址且是IPV4时
if (!inetAddress.isLoopbackAddress && inetAddress is Inet4Address) {
return inetAddress.getHostAddress()
}
}
}
} catch (e: SocketException) {
return null
e.printStackTrace()
}
return null
}
::1 IPv6形式,对应IPV4的127.0.0.1
127.0.0.1
fe80::c4eb:7d14:a746:a087%wlan0
192.168.20.20
该方法仅适用于只开启了移动流量未开启WIFI的时候使用,因为我们在遍历并判断是IPV4的地址时,获取到了第一个就直接返回了,而且该方法获取到的也是内网A类地址
while (inetAddressEnumeration.hasMoreElements()) {
val inetAddress = inetAddressEnumeration.nextElement()
//当不是回路地址且是IPV4时
if (!inetAddress.isLoopbackAddress && inetAddress is Inet4Address) {
return inetAddress.getHostAddress()
}
}
当同时连接WIFI和移动流量时,将其打印,可以得到以下地址
10.98.193.41
192.168.137.21
public abstract class LiveData<T> {
// 暂存值字段
volatile Object mPendingData = NOT_SET;
private final Runnable mPostValueRunnable = new Runnable() {
@Override
public void run() {
Object newValue;
synchronized (mDataLock) {
// 同步地获取暂存值
newValue = mPendingData;
mPendingData = NOT_SET;
}
// 分发值
setValue((T) newValue);
}
};
protected void postValue(T value) {
boolean postTask;
synchronized (mDataLock) {
postTask = mPendingData == NOT_SET;
// 暂存值
mPendingData = value;
}
...
// 向主线程抛 runnable
ArchTaskExecutor.getInstance().postToMainThread(mPostValueRunnable);
}
}