Reputation: 13051
I'm developing an app with a WebView
that loads some content from the web.
What I'm trying to do is to detect every Wi-Fi change (connected or not connected) and show a dialog if Wi-Fi is not connected or the content of the WebView
if it is connected.
I implemented a BroadcastReceiver
with action android.net.wifi.WIFI_STATE_CHANGED
:
public class SyncOfflineDataOnWifiReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = (NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info!=null && info.getDetailedState() == DetailedState.CONNECTED) {
Application.setInternet(true);
}else{
Application.setInternet(false);
}
}
}
So when Wi-Fi connects flag boolean Internet
is set to true
(otherwise false
).
What I need is a module that tries to reconnect to the same Wi-Fi (the saved one) till it is not connected. Is possible to have something like this? Thanks!
Upvotes: 0
Views: 170
Reputation: 18358
Of course it's possible. It's in the WiFi manager API. Review it, especially the reassociate()
and reconnect()
methods: http://developer.android.com/reference/android/net/wifi/WifiManager.html
Upvotes: 1