Skip to content

Instantly share code, notes, and snippets.

@basil2style
Last active May 25, 2018 16:32
Show Gist options
  • Select an option

  • Save basil2style/a99afe33ba7b8df6ee95 to your computer and use it in GitHub Desktop.

Select an option

Save basil2style/a99afe33ba7b8df6ee95 to your computer and use it in GitHub Desktop.
This will Check Internet Connected or not
if(isOnline()){
Toast.maketext(this,"Network Connected",Toast.LENGTH_SHORT).show();
}
else{
Toast.maketext(this,"No Network Connection",Toast.LENGTH_SHORT).show();
}
public boolean isOnline(){
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if(netInfo !=null && netinfo.isConnectedorConnecting()){
return true;
}else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment