Skip to content

Instantly share code, notes, and snippets.

@mingcheng
Created November 30, 2012 04:07
Show Gist options
  • Select an option

  • Save mingcheng/4173722 to your computer and use it in GitHub Desktop.

Select an option

Save mingcheng/4173722 to your computer and use it in GitHub Desktop.
Android 检查网络状态
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