ide/androidstudio

Android Networking Connect

C/H 2016. 12. 27. 08:30

private boolean isNetworkConnected() {
    ConnectivityManager connMgr = (ConnectivityManager)
           getSystemService(Context.CONNECTIVITY_SERVICE); // 1
     NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); // 2
     return networkInfo != null && networkInfo.isConnected(); // 3
}

private boolean isWifiConnected() {
  ConnectivityManager connMgr = (ConnectivityManager)
              getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
  return networkInfo != null && (ConnectivityManager.TYPE_WIFI == networkInfo.getType()) && networkInfo.isConnected();
}


반응형

'ide > androidstudio' 카테고리의 다른 글

ReactivceX, RxAndroid  (0) 2017.01.02
okhttp3  (0) 2016.12.28
현재 메소드 명  (0) 2016.12.23
com.jakewharton:butterknife:8.4.0 @BindView 에러  (0) 2016.12.22
rxAndroid rxlifecycle RetroLambda, Lambda Error  (0) 2016.12.21