Android 的 WifiInfo#getSSID() : is there a way to understand if SSID has double quotes by itself or is it Android created ones?

标签 android android-wifi ssid

根据 getSSID 方法的文档:

Returns the service set identifier (SSID) of the current 802.11 network. If the SSID can be decoded as UTF-8, it will be returned surrounded by double quotation marks. Otherwise, it is returned as a string of hex digits. The SSID may be {@code null} if there is no network currently connected.

此方法的源代码在一定程度上符合文档(null 情况除外),因此我不会将其作为代码 fragment 附在此处,but here it is for API 21 .

看来我可以删除双重代码,但根据this SO question , WifiInfogetSSID() 方法可以说Android 版本之间的实现可能不同

关于 SSID 的非正式消息来源提到它是字母数字,但我发现了一个有争议的说法:根据 this source , SSID 可以包含双引号,所以它是一个有效的字符。

因此,UTF-8 编码的 SSID 要么用双引号括起来,要么不用

问题:这是一种可靠方法来识别 SSID 是否在结尾和开头都包含双引号,或者它来自 android 的 getSSID 实现?

最佳答案

WifiInfo.getSSID() 返回字符串,因此您可以为此使用 String.matches 和 String.replace

检测:

String ssid = "\"MYSSID\"";
Boolean matches = ssid.matches("^\".*\"$");
Log.v("Check quotes", "Matching " + matches);

删除:

ssid = ssid.replace("\"", "");

关于Android 的 WifiInfo#getSSID() : is there a way to understand if SSID has double quotes by itself or is it Android created ones?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53284899/

相关文章:

android - 帮助点对点wifi

android - Intent 打开 Wi-Fi Direct 设置

android - 可以过滤 WifiManager 的扫描吗?

java - 处理 View(State)PagerAdapter 内 Fragment 内 Fragment 的屏幕旋转

android - 无法解析构造函数 'Intent(xxxx.xx.java.lang.thread.Class<com.practice.MainActivity>)'

android - 相机 2 API 视频录制 - 自动闪光不工作

Android > 4.0 fragment 和标签

android - 使用 adb 连接 WIFI

wifi - 扫描wifi结果重复SSID

android - WifiInfo 返回 null