I am referring to a situation when device is connected to access point but for some reason is blocked from accessing internet using this AP.
Asked
Active
Viewed 1,414 times
3 Answers
1
for check wifi is enabled or not
WifiManager wfManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if(wfManager.isWifiEnabled())
{
//Code
}
else
{
//Code
}
for check internet connection..
public boolean isOnline()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting())
{
//Try This
int i =netInfo.getType() ;
System.out.println("Net Type ="+i);
return true;
}
return false;
}

Niranj Patel
- 32,980
- 10
- 97
- 133
-
This is not exactly what I need - state CONNECTED for WiFi connection means that the device is connected to the AP but not necessarily can access Internet – Asahi Apr 30 '11 at 09:29
-
netInfo.getType() ; try this but exactly i didnt used this so i dont know which value for wifi or mobile internet.. for more info u can follow this link..http://developer.android.com/reference/android/net/NetworkInfo.html#getType%28%29 – Niranj Patel Apr 30 '11 at 09:47
-
not really, dear... all these API provide info about connection to the AP but there is no way to identify whether it can go any further. Still looking... – Asahi Apr 30 '11 at 10:43
-
i think its reply only two value so can test one by one using net with wifi n mobile's net.. so u can understand exactly which value for wifi or mobile.. – Niranj Patel Apr 30 '11 at 10:46
0
private boolean connectionAvailable() {
boolean connected = false;
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
//we are connected to a network
connected = true;
}
return connected;
}

Dharmendra
- 33,296
- 22
- 86
- 129
-
This is not exactly what I need - state CONNECTED for WiFi connection means that the device is connected to the AP but not necessarily can access Internet – Asahi Apr 30 '11 at 09:21
-
Ok so you want to check that wifi is accessing the internet or not. i have no idea for that. – Dharmendra Apr 30 '11 at 09:26
0
These look like something that can solve the problem:
How to do a true Java ping from Windows?