Skip to content

Instantly share code, notes, and snippets.

@BALUSANGEM
Created January 5, 2016 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BALUSANGEM/2c599c8c68ef54575f31 to your computer and use it in GitHub Desktop.
Save BALUSANGEM/2c599c8c68ef54575f31 to your computer and use it in GitHub Desktop.
//Give Your PackageName Ex:com.companyname.projectname;
package com.pgeek.sample;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class ConnectionDetector {
private Context _context;
public ConnectionDetector(Context context){
this._context = context;
}
/**
* Checking for all possible internet providers
* **/
public boolean isConnectingToInternet(){
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
//Returns True if Device has Internet Connection
return true;
}
}
//Returns False if Device has No Internet Connection
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment