Skip to content

Instantly share code, notes, and snippets.

@avew
Created November 21, 2014 06:38
Show Gist options
  • Select an option

  • Save avew/739317a9d54873efb3c3 to your computer and use it in GitHub Desktop.

Select an option

Save avew/739317a9d54873efb3c3 to your computer and use it in GitHub Desktop.
Cek internet Koneksi Android
public final boolean isInternetOn() {
// get Connectivity Manager object to check connection
ConnectivityManager connec =
(ConnectivityManager) getSystemService(getBaseContext().CONNECTIVITY_SERVICE);
// Check for network connections
if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED) {
// if connected with internet
avew.showAlertDialog(AwalActivity.this, "Internet Connection",
"You have internet connection", true);
return true;
} else if (
connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED) {
avew.showAlertDialog(AwalActivity.this, "No Internet Connection",
"You don't have internet connection.", false);
return false;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment