I'm currently working on an application that needs to know whether the phone has internet connection.
Using Connectivity Manager the app is able to generate an event when there is or there is no network connection. Problem is, I need to be connected to a WI-FI local hotspot for my app, and this WI-FI does not offer internet access. to summarise, ConnectivityManager tells me there is internet connection because i'm connected to this wi-fi, but this wi-fi does not offer a real connection.
Here is the code :
public void onReceive(Context context, Intent intent) {
if(intent == null || intent.getExtras() == null)
return;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = manager.getActiveNetworkInfo();
if(ni != null && ni.getState() == NetworkInfo.State.CONNECTED) {
connected = true;
} else if(intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,Boolean.FALSE)) {
connected = false;
}
notifyStateToAll();
}
Is there a way to specify ConnectivityManager that one special Wi-Fi does not offer internet access?