當前位置: 首頁>>代碼示例>>Java>>正文


Java NetworkInfo.isConnectedOrConnecting方法代碼示例

本文整理匯總了Java中android.net.NetworkInfo.isConnectedOrConnecting方法的典型用法代碼示例。如果您正苦於以下問題:Java NetworkInfo.isConnectedOrConnecting方法的具體用法?Java NetworkInfo.isConnectedOrConnecting怎麽用?Java NetworkInfo.isConnectedOrConnecting使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.NetworkInfo的用法示例。


在下文中一共展示了NetworkInfo.isConnectedOrConnecting方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: haveInternet

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean haveInternet(Context context) {
    //Obtem o gerenciador de conectividade do sistema
    ConnectivityManager lConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    //Obtem a informação de rede
    NetworkInfo lNetworkInfo = lConnectivityManager.getActiveNetworkInfo();

    //Retorna se está conectado ou não
    return lNetworkInfo != null && lNetworkInfo.isConnectedOrConnecting();
}
 
開發者ID:alessandrojean,項目名稱:order-by-android,代碼行數:10,代碼來源:Utils.java

示例2: isConnecting

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean isConnecting(Context mContext) {
    ConnectivityManager manager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()
            || !networkinfo.isConnectedOrConnecting()) {
        return false;
    }
    return true;
}
 
開發者ID:bigjelly,項目名稱:AndFast,代碼行數:14,代碼來源:NetworkUtils.java

示例3: IsNetworkAvailable

import android.net.NetworkInfo; //導入方法依賴的package包/類
public boolean IsNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
        return false;
    }

    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:10,代碼來源:NetworkController.java

示例4: isThereInternetConnection

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Checks if the device has any active internet connection.
 *
 * @return true device with internet connection, otherwise false.
 */
private boolean isThereInternetConnection() {
  boolean isConnected;

  ConnectivityManager connectivityManager =
      (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
  isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());

  return isConnected;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:RestApiImpl.java

示例5: isConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean isConnected() {
    ConnectivityManager cm = (ConnectivityManager) MyApplication.getInstance().getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null
            && activeNetwork.isConnectedOrConnecting();
}
 
開發者ID:CSI-KJSCE,項目名稱:CSI-KJSCEOfficial,代碼行數:8,代碼來源:ConnectivityReceiver.java

示例6: isOnline

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean isOnline(Context context) {
    try {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
                ("connectivity")).getActiveNetworkInfo();
        if (activeNetworkInfo != null) {
            return activeNetworkInfo.isConnectedOrConnecting();
        }
        return false;
    } catch (Exception e) {
        return true;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:13,代碼來源:DeviceConfig.java

示例7: isConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean isConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager)
            context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = null;
    if (connectivityManager != null) {
        networkInfo = connectivityManager.getActiveNetworkInfo();
    }
    return networkInfo != null && networkInfo.isConnectedOrConnecting();
}
 
開發者ID:TigranSarkisian,項目名稱:Boilerplate,代碼行數:10,代碼來源:NetworkUtil.java

示例8: checkConnection

import android.net.NetworkInfo; //導入方法依賴的package包/類
public boolean checkConnection(){   //method for checking network connection
    ConnectivityManager cm =
            (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null &&
            activeNetwork.isConnectedOrConnecting();
    return isConnected;
}
 
開發者ID:amir511,項目名稱:My-Sheep,代碼行數:10,代碼來源:MainActivity.java

示例9: isNetworkAvailable

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Check for internet connection
 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm =
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
 
開發者ID:graviton57,項目名稱:TheNounProject,代碼行數:10,代碼來源:AppUtils.java

示例10: updateFromPreferences

import android.net.NetworkInfo; //導入方法依賴的package包/類
public void updateFromPreferences(SharedPreferences prefs) {
    // in case server url has changed reconnect
    if (mServerURL == null || !mServerURL.equalsIgnoreCase(prefs.getString("pref_url", ""))) {
        mServerURL = prefs.getString("pref_url", "");
        close();
    }

    ConnectivityManager cm = (ConnectivityManager) mCtx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
        connect();
    } else {
        close();
    }
}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:16,代碼來源:ServerConnection.java

示例11: isConnectedOrConnecting

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * 判斷有無網絡正在連接中(查找網絡、校驗、獲取IP等)。
 *
 * @return boolean 不管wifi,還是mobile net,隻有當前在連接狀態(可有效傳輸數據)才返回true,反之false。
 */
public static boolean isConnectedOrConnecting(Context context) {
    NetworkInfo[] nets = getConnectivityManager(context).getAllNetworkInfo();
    if (nets != null) {
        for (NetworkInfo net : nets) {
            if (net.isConnectedOrConnecting()) { return true; }
        }
    }
    return false;
}
 
開發者ID:androidDaniel,項目名稱:treasure,代碼行數:15,代碼來源:Network.java

示例12: getCurrentNetState

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * get the net state of current
 * @param context the context.
 * @return the state code. see {@linkplain #STATE_2G} and etc.
 */
public static byte getCurrentNetState(Context context) {
    byte code = STATE_NO;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni != null && ni.isConnectedOrConnecting()) {
        switch (ni.getType()) {
            //wifi
            case ConnectivityManager.TYPE_WIFI:
                code = STATE_WIFI;
                break;
            //mobile 網絡
            case ConnectivityManager.TYPE_MOBILE:
                switch (ni.getSubtype()) {
                    case TelephonyManager.NETWORK_TYPE_GPRS: //聯通2g
                    case TelephonyManager.NETWORK_TYPE_CDMA: //電信2g
                    case TelephonyManager.NETWORK_TYPE_EDGE: //移動2g
                    case TelephonyManager.NETWORK_TYPE_1xRTT:
                    case TelephonyManager.NETWORK_TYPE_IDEN:
                        code = STATE_2G;
                        break;
                    case TelephonyManager.NETWORK_TYPE_EVDO_A: //電信3g
                    case TelephonyManager.NETWORK_TYPE_UMTS:
                    case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    case TelephonyManager.NETWORK_TYPE_HSDPA:
                    case TelephonyManager.NETWORK_TYPE_HSUPA:
                    case TelephonyManager.NETWORK_TYPE_HSPA:
                    case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    case TelephonyManager.NETWORK_TYPE_EHRPD:
                    case TelephonyManager.NETWORK_TYPE_HSPAP:
                        code = STATE_3G;
                        break;
                    case TelephonyManager.NETWORK_TYPE_LTE://4G
                        code = STATE_4G;
                        break;

                    default:
                        code = STATE_UNKNOWN;
                }
                break;
            default:
                code = STATE_UNKNOWN;
        }
    }
    return code;
}
 
開發者ID:LightSun,項目名稱:android-util2,代碼行數:51,代碼來源:NetHelper.java

示例13: isNetworkConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm =
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
 
開發者ID:MindorksOpenSource,項目名稱:android-mvvm-architecture,代碼行數:7,代碼來源:NetworkUtils.java

示例14: isNetworkConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
private boolean isNetworkConnected() {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting();
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:6,代碼來源:SealUserInfoManager.java

示例15: isNetworkConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
private boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting();
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:6,代碼來源:SplashActivity.java


注:本文中的android.net.NetworkInfo.isConnectedOrConnecting方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。