Browse Source

[new]优化wifi名称获取

zk 6 months ago
parent
commit
408ae771d1
1 changed files with 17 additions and 1 deletions
  1. 17 1
      lib/helper/internet_connection_helper.dart

+ 17 - 1
lib/helper/internet_connection_helper.dart

@@ -91,13 +91,29 @@ class InternetConnectionHelper {
     if (!await PermissionUtil.checkLocationPermission()) {
       return null;
     }
-    final wifiName = await wifiInfo.getWifiName();
+    String? wifiName = await wifiInfo.getWifiName();
+    wifiName = clean(wifiName);
     AtmobLog.d(tag, 'wifi名称:$wifiName');
+
     _networkName = wifiName;
     atmobPlatformInfo.setWifiName(wifiName);
     return wifiName;
   }
 
+  static String? clean(String? ssid) {
+    if (ssid == null || ssid.trim().isEmpty) return null;
+
+    String trimmed = ssid.trim();
+
+    if (trimmed.startsWith('"') &&
+        trimmed.endsWith('"') &&
+        trimmed.length >= 2) {
+      return trimmed.substring(1, trimmed.length - 1);
+    }
+
+    return trimmed;
+  }
+
   void _setMobileNetworkName() {
     _networkName = Constants.kMobileNetworkTag;
   }