Search code examples
androidcaptivenetworkcaptiveportal

Is the string "captive_portal_detected" from NetworkInfo getExtraInfo() a reliable indication of captive portal?


I have a Samsung 6.0.1 that I am using in my development. I want to know if a network is captive portal. There have been recent changes that make this info known to the developer, which is nice. But there doesn't seem to be a way to just retrieve the data from NetworkInfo.

I have found that if I can get my hands on an instance of Wi-Fi NetworkInfo I can call getExtraInfo and an indication of captive portal will be in there as a string "captive_portal_detected" It's weird this is a string and not a boolean property, but that's not my question.

What version of Android did this string start popping up and is this part of the regular OS or something the Samsung guys popped in for the s7? Can I rely on this string as an indicator that the access point associated with the NetworkInfo is in fact captive portal? There is no documentation on this value that I can find anywhere.


Solution

  • In the documentation it tells that the return of the method getExtraInfo returns the information provided by the lower network layers: http://developer.android.com/intl/pt-br/reference/android/net/NetworkInfo.html#getExtraInfo()

    So if getExtraInfo will return if it is in a captive portal its determined by the network hardware, I recommend that you avoid being dependent of detemined hardware.

    Here are an example of how to discover if the user are in captive portal: How to check for unrestricted Internet access? (captive portal detection)