Created
July 15, 2014 16:38
-
-
Save PepeuCps/fb0b794c201cc8b77ee6 to your computer and use it in GitHub Desktop.
Verifica se o device está conectado na internet (3G ou WIFI).
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 hasConnection(Context context) { | |
try { | |
ConnectivityManager cm = (ConnectivityManager) | |
context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()) { | |
Log.i("hasConnection","Status de conexao 3G: " + cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()); | |
return true; | |
} else if(cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()){ | |
Log.i("hasConnection","Status de conexao Wifi: " + cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()); | |
return true; | |
} else { | |
Log.i("hasConnection","Status de conexao Wifi: " + cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()); | |
Log.i("hasConnection","Status de conexao 3G: " + cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()); | |
return false; | |
} | |
} catch (Exception e) { | |
Log.e("hasConnection", "Exception hasConnection " + e.getMessage()); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment