Created
November 22, 2017 15:31
-
-
Save sagorbrur/98fe69632c6908179f67745c7af425d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import android.app.Service; | |
import android.content.Context; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
/** | |
* Created by Sagor Sarker on 17-Nov-17. | |
*/ | |
public class ConnectionDetector { | |
Context context; | |
public ConnectionDetector(Context context) { | |
this.context = context; | |
} | |
public boolean isConnected() | |
{ | |
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Service.CONNECTIVITY_SERVICE); | |
if(cm!=null){ | |
NetworkInfo info = cm.getActiveNetworkInfo(); | |
if(info!=null){ | |
if(info.getState() == NetworkInfo.State.CONNECTED) | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment