4

According to documentation of the getSSID method:

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.

Source code of this method does somewhat conform to the documentation (except of null case), so I won't attach it here as a code snippet, but here it is for API 21.

It seems I can just remove double codes, but according to this SO question, getSSID() method of WifiInfo it can be said that implementation can vary between android versions.

Casual sources about SSID mention that it is alphanumeric, but I found a controversial statement: according to this source, SSID can contain double quotes, so it is a valid character.

As a result, UTF-8 encoded SSID can either be wrapped with double quotes or not to be.

Question: is here a reliable way to identify if SSID contain double quotes at both the end and the start, or it comes from android's getSSID implementation?

nyarian
  • 4,085
  • 1
  • 19
  • 51

2 Answers2

3

WifiInfo.getSSID() returns String so you can use String.matches and String.replace for this

To detect:

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

To remove:

ssid = ssid.replace("\"", "");
Terje Rosenlund
  • 153
  • 1
  • 9
1

A simple solution in Kotlin would be something like this

ssid = ssid.removeSurrounding("\"")

which will take care of removing the leading and trailing double quotes if they were found.

Hamza Sharaf
  • 811
  • 9
  • 25