Android Wi-Fi Scan: Filter printers from ScanResult
Asked Answered
S

2

11

I am working on a project, that needs to scan for public Wi-Fi access points.

Currently, I am filtering the ScanResult like this:

for (ScanResult scanResult : wifiList) {
  if (!(scanResult.capabilities.contains("WEP") || 
        scanResult.capabilities.contains("WPA") || 
        scanResult.capabilities.contains("WPA2"))) {

              openWifiList.add(scanResult);    

  }
}

It works fine, except that I also get printers that are nearby.

While scanning, the phone is not connected to any network.

I would have assumed that I get a list that is identically with the list of Wi-Fi connections that is shown in the Wi-Fi Settings on Android. But in the Wi-Fi Setting there is no printer shown ever.

So for 1) I think it is strange that printers show up in the ScanResult list at all, should printers really be visible that way?


UPDATE: not all Wi-Fi printers are visible, I got some hints on that, and it seems like the printers that are showing up, do have a special functionality, e.g. HP printers support the HP Wireless Direct functionality (see e.g. https://h30434.www3.hp.com/t5/Inkjet-Printing/Printer-SSID-appearing-on-my-wi-fi-list/td-p/1705073 and https://support.hp.com/rs-en/document/c04577030).


And 2) is there any way that I could check whether the ScanResult belongs to a printer?

So far I could only think of filtering for common SSID names, but that will not be very efficient or reliable.

Thanks for any suggestions.

Sams answered 12/7, 2017 at 10:16 Comment(2)
Check if the capabilities field of ScanResult can be of any help.Unconsidered
@AshishPathak that was of course one of the first things I have tried. It only shows capability "ESS" which is also a capability of "normal" access points.Sams
T
4

1) Not all printers support the WiFi Direct protocol, HP supports this and also their proprietary protocol you've mentioned (HP Wireless Direct), though your device probably doesn't support it without HP software.

Learn more about connecting to WiFi Direct protocol from Android here.

2) WiFi direct discovery returns String fullDomain, if it contains _ipp - that's most likely a printer.

Trajectory answered 20/7, 2017 at 14:55 Comment(3)
thanks for the suggestions, @auval! I will try to use this one, however, it would require to setup another callback, that I somehow need to validate with the received ScanResults from the broadcast receiver, right? I will test it, but I think this will be too much overhead for this project.. If the "_ipp" is only kind of an indicator, I guess I could also just filter SSIDs that begin with "HP-" or something like thatSams
The API I've pointed you to (P2P) will show equipment supporting WiFi direct. Use the list you got with the standard WiFi manager to get the list of all devices, then you can use the P2P API to subtract the printers (comparing SSID).Trajectory
SSID isn't something you can rely on. "HP-"" is probably related to any HP hardware, not necessarily printers.Trajectory
M
0

I found there is a property, good for filtering.

WifiP2pDevice.primaryDeviceType

You may find the device type here: https://ndeflib.readthedocs.io/en/stable/records/wifi.html#primary-device-type

enter image description here


Edited

It's found the primaryDeviceType is a string of numbers like this: 7-0050f204-1

Please refer to Wifi Alliance spec in this link: https://www.wi-fi.org/file/wi-fi-simple-configuration-technical-specification-v206

Merci answered 2/7, 2019 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.