Skip to content

Instantly share code, notes, and snippets.

@sakurabird
Created October 7, 2013 14:38
Show Gist options
  • Save sakurabird/6869087 to your computer and use it in GitHub Desktop.
Save sakurabird/6869087 to your computer and use it in GitHub Desktop.
Androidのネットワーク接続チェック
/**
* ネットワーク接続チェック
*
* @param context
* @return
*/
public static boolean isConnected() {
ConnectivityManager cm = (ConnectivityManager) MyApplication.getContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni != null) {
return cm.getActiveNetworkInfo().isConnected();
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment