当前位置: 首页>>代码示例>>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;未经允许,请勿转载。