'WiFi suggestion API fail on Android
I've been trying to use the new Android WiFi Suggestion API with the code taken exactly from the example, but each time I try to connect to a network, when I call wifiManager.addNetworkSuggestions(suggestionsList)
I get status 3 in response, which (according to this site) means IP provision failure. What does that mean? How can I handle that?
My app has all the required permissions and even some more (CHANGE_WIFI_STATE
, ACCESS_WIFI_STATE
, INTERNET
, ACCESS_FINE_LOCATION
, CHANGE_NETWORK_STATE
, ACCESS_NETWORK_STATE
), and the location is turned on. I tried with a few WiFi networks (all are visible in the WiFi settings), but still got the same IP provisioning error.
Solution 1:[1]
Had the same issue and found it quite confusing because status = 3
can mean two things: STATUS_SUGGESTION_APPROVAL_REJECTED_BY_USER
or STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE
.
In my case it was the latter. Basically the suggestion is remembered once submitted. I solved this by removing my suggestion before it's added:
wifiManager.removeNetworkSuggestions(suggestions)
val status = wifiManager.addNetworkSuggestions(suggestions)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ya man |