diff --git a/app/src/main/java/com/ichtj/basetools/OptionAty.java b/app/src/main/java/com/ichtj/basetools/OptionAty.java index 7988432..de38b38 100644 --- a/app/src/main/java/com/ichtj/basetools/OptionAty.java +++ b/app/src/main/java/com/ichtj/basetools/OptionAty.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; +import android.util.Log; import android.view.View; import androidx.annotation.NonNull; diff --git a/base_iotutils/src/main/java/com/face_chtj/base_iotutils/NetUtils.java b/base_iotutils/src/main/java/com/face_chtj/base_iotutils/NetUtils.java index 6e3b03c..2f487f8 100644 --- a/base_iotutils/src/main/java/com/face_chtj/base_iotutils/NetUtils.java +++ b/base_iotutils/src/main/java/com/face_chtj/base_iotutils/NetUtils.java @@ -885,9 +885,23 @@ public static String getEthIPv4Address() { } } } else { - // For versions before Android M, there is no direct API to get Ethernet information. - // You may need to use reflection or other methods to check Ethernet connectivity. - //Log.w(TAG, "Android version is too low to directly get Ethernet information."); + try{ + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = networkInterfaces.nextElement(); + if (networkInterface.getName().equals("eth0") || networkInterface.getName().equals("wlan0")) { // 可能是eth0或wlan0 + Enumeration inetAddresses = networkInterface.getInetAddresses(); + while (inetAddresses.hasMoreElements()) { + InetAddress inetAddress = inetAddresses.nextElement(); + if (!inetAddress.isLoopbackAddress() && inetAddress.getAddress().length == 4) { + return inetAddress.getHostAddress(); + } + } + } + } + }catch(Throwable throwable){ + throwable.printStackTrace(); + } } return null; } diff --git a/config.gradle b/config.gradle index db8a610..fe01c9e 100644 --- a/config.gradle +++ b/config.gradle @@ -1,6 +1,6 @@ ext { //选择对应签名 "cainiao" "rockchip" "imx8" "freescale" - BUILD_SIGN="rockchip" + BUILD_SIGN="freescale" BUILD_SIGN_PWD="android" BUILD_SIGN_PATH="../other/facefuture.jks" //android开发版本配置