Created
January 25, 2016 08:40
-
-
Save hassantafreshi/1ba7bb19d196e0db61de to your computer and use it in GitHub Desktop.
Check Internet connection Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class connection { | |
private boolean haveConnectedWifi = false; | |
private boolean haveConnectedMobile = false; | |
private boolean haveNetworkConnection() { | |
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo[] netInfo = cm.getAllNetworkInfo(); | |
for (NetworkInfo ni : netInfo) { | |
if (ni.getTypeName().equalsIgnoreCase("WIFI")) | |
if (ni.isConnected()) | |
haveConnectedWifi = true; | |
if (ni.getTypeName().equalsIgnoreCase("MOBILE")) | |
if (ni.isConnected()) | |
haveConnectedMobile = true; | |
} | |
return haveConnectedWifi || haveConnectedMobile; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment