Created
November 30, 2012 04:07
-
-
Save mingcheng/4173722 to your computer and use it in GitHub Desktop.
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 void myClickHandler(View view) { | |
| ... | |
| ConnectivityManager connMgr = (ConnectivityManager) | |
| getSystemService(Context.CONNECTIVITY_SERVICE); | |
| NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); | |
| if (networkInfo != null && networkInfo.isConnected()) { | |
| // fetch data | |
| } else { | |
| // display error | |
| } | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment