Created
November 21, 2014 06:38
-
-
Save avew/739317a9d54873efb3c3 to your computer and use it in GitHub Desktop.
Cek internet Koneksi Android
This file contains hidden or 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 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