Created
January 1, 2014 12:03
-
-
Save ishitcno1/8207397 to your computer and use it in GitHub Desktop.
Android methods to check the network connection.
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 static boolean isWifiConn(Context context) { | |
ConnectivityManager connectivityManager = (ConnectivityManager) | |
context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo networkInfo = connectivityManager | |
.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | |
return networkInfo.isConnected(); | |
} | |
public static boolean isMobileConn(Context context) { | |
ConnectivityManager connectivityManager = (ConnectivityManager) | |
context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo networkInfo = connectivityManager | |
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | |
return networkInfo.isConnected(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment