GAMES PC DOWNLOAD FREE FULL

GAME

How to check if the phone is connected to the Internet

 

to check whether your phone is connected to the Internet, use the following code:
ConnectivityManager con=(ConnectivityManager)getSystemService(Activity.CONNECTIVITY_SERVICE);
boolean wifi=con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
boolean internet=con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();

these lines check for internet connection whether it is through WiFi or Mobile Internet.

you need to add the following permission to the AndroidManifest.xml file
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Another method is what our freind Kevin mentioned in the comments, is to check if a certain website is reachable or not like this:
public static boolean isOnline() {
try {
InetAddress.getByName("google.ca").isReachable(3);
return true;
} catch (UnknownHostException e){
return false;
} catch (IOException e){
return false;
}
}

we check if a site is reachable within a certain timeout or not.
How to check if the phone is connected to the Internet 4.5 5 Thanh Nguyen to check whether your phone is connected to the Internet, use the following code: ConnectivityManager con=(ConnectivityManager)getSystemServ...


No comments:

Post a Comment

NEW GAME

Powered by Blogger.

Labels

Quotes

1. Những cô gái giống như những tên miền Internet, những tên đẹp mà ta thích đã có chủ nhân rồi!


Popular Posts