Advertisement
sandi_s

Pendeteksi_koneksi.java

Feb 17th, 2018
1,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package lokadin.sandy.example.com.lokadin;
  2. import android.content.Context;
  3. import android.net.ConnectivityManager;
  4. import android.net.NetworkInfo;
  5. /**
  6.  * Created by sandy on 7/9/2017.
  7.  */
  8. public class Pendeteksi_koneksi {
  9.     private Context _context;
  10.     public Pendeteksi_koneksi(Context context) {
  11.         this._context = context;
  12.     }
  13.     public boolean isConnectingToInternet() {
  14.         ConnectivityManager connectivity = (ConnectivityManager) _context
  15.                 .getSystemService(Context.CONNECTIVITY_SERVICE);
  16.         if (connectivity != null) {
  17.             NetworkInfo[] info = connectivity.getAllNetworkInfo();
  18.             if (info != null)
  19.                 for (int i = 0; i < info.length; i++)
  20.                     if (info[i].getState() == NetworkInfo.State.CONNECTED) {
  21.                         return true;
  22.                     }
  23.         }
  24.         return false;
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement