Advertisement
jajangjaenalyusup

Cek Koneksi Internet

Dec 19th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. /*
  2.  * Class untuk pengecekan internet
  3.  * author : androidhive.info
  4.  */
  5. import android.content.Context;
  6. import android.net.ConnectivityManager;
  7. import android.net.NetworkInfo;
  8.  
  9. public class ConnectionDetector {
  10.  
  11.     private Context _context;
  12.  
  13.     public ConnectionDetector(Context context) {
  14.         this._context = context;
  15.     }
  16.  
  17.     public boolean isConnectingToInternet() {
  18.         ConnectivityManager connectivity = (ConnectivityManager) _context
  19.                 .getSystemService(Context.CONNECTIVITY_SERVICE);
  20.         if (connectivity != null) {
  21.             NetworkInfo[] info = connectivity.getAllNetworkInfo();
  22.             if (info != null)
  23.                 for (int i = 0; i < info.length; i++)
  24.                     if (info[i].getState() == NetworkInfo.State.CONNECTED) {
  25.                         return true;
  26.                     }
  27.  
  28.         }
  29.         return false;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement