Created
January 5, 2016 17:23
-
-
Save BALUSANGEM/2c599c8c68ef54575f31 to your computer and use it in GitHub Desktop.
This file contains 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
//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