Advertisement
Guest User

Util.java

a guest
May 4th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import android.content.Context;
  2. import android.net.ConnectivityManager;
  3. import android.net.NetworkInfo;
  4.  
  5. /**
  6. * Created by Yayangrzv on 5/4/2015.
  7. */
  8. public class Util {
  9. public static boolean isOnline(Context context) {
  10. try {
  11. ConnectivityManager connectivity = (ConnectivityManager) context
  12. .getSystemService(Context.CONNECTIVITY_SERVICE);
  13. if (connectivity != null) {
  14. NetworkInfo[] info = connectivity.getAllNetworkInfo();
  15. if (info != null) {
  16. for (int i = 0; i < info.length; i++) {
  17. if (info[i].getState() == NetworkInfo.State.CONNECTED) {
  18. return true;
  19. }
  20. }
  21. }
  22. }
  23. } catch (Exception e) {
  24. }
  25. return false;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement