当前位置: 首页>>代码示例>>Java>>正文


Java NetworkInfo.getTypeName方法代码示例

本文整理汇总了Java中android.net.NetworkInfo.getTypeName方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInfo.getTypeName方法的具体用法?Java NetworkInfo.getTypeName怎么用?Java NetworkInfo.getTypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.NetworkInfo的用法示例。


在下文中一共展示了NetworkInfo.getTypeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNetworkTypeName

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * Get network type name
 *
 * @param context
 * @return
 */
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    }

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
                    : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:NetUtil.java

示例2: isWifiConnectivityType

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * @brief Checks the connectivity type of the terminal
 * @return True if the connectivity type is Wifi, false in another case.
 * @details Checks the connectivity type of the terminal
 */
//devuelve true si es conexion wifi, false en caso contrario
private boolean isWifiConnectivityType(){
	ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
       NetworkInfo info = connectivityManager.getActiveNetworkInfo();
       
       String connectionType = info.getTypeName();
       
       if (connectionType.equalsIgnoreCase("wifi")){
       	return true;
       }
       else{
       	//3g u otro tipo
       	return false;
       }
       	
}
 
开发者ID:CodyyAndroid,项目名称:LibVNCAndroid,代码行数:22,代码来源:ActivityTabs.java

示例3: getNetworkTypeName

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * Get network type name
 * 
 * @param context
 * @return
 */
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    }

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
                    : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:NetWorkUtils.java

示例4: p

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String p(Context context) {
    try {
        if (a(context, "android.permission.INTERNET") && a(context, "android.permission" +
                ".ACCESS_NETWORK_STATE")) {
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
                    ("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
                String typeName = activeNetworkInfo.getTypeName();
                String extraInfo = activeNetworkInfo.getExtraInfo();
                if (typeName != null) {
                    return typeName.equalsIgnoreCase("WIFI") ? "WIFI" : typeName
                            .equalsIgnoreCase("MOBILE") ? extraInfo == null ? "MOBILE" :
                            extraInfo : extraInfo == null ? typeName : extraInfo;
                }
            }
            return null;
        }
        f.e((Object) "can not get the permission of android.permission.ACCESS_WIFI_STATE");
        return null;
    } catch (Object th) {
        f.e(th);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:24,代码来源:k.java

示例5: getNetworkConnectedType

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * 获取设备网络连接状态,并且包含网络类型:2G/(3G/4G)/WIFI
 * 返回值:NETWORKTYPE_INVALID,NETWORKTYPE_WAP,NETWORKTYPE_2G,NETWORKTYPE_3G,NETWORKTYPE_WIFI
 * @param context
 * @return
 */
public static int getNetworkConnectedType(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        String type = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(type)) {
            return NETWORKTYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(type)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            if (TextUtils.isEmpty(proxyHost)) {
                return isFastMobileNetwork(context) ? NETWORKTYPE_3G : NETWORKTYPE_2G;
            } else {
                return NETWORKTYPE_WAP;
            }
        } else {
            return NETWORKTYPE_INVALID;
        }
    } else {
        return NETWORKTYPE_INVALID;
    }
}
 
开发者ID:ymqq,项目名称:CommonFramework,代码行数:28,代码来源:NetworkStatusUtils.java

示例6: getNetworkTypeName

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * Get network type name
 *
 * @param context context
 * @return Network type name
 */
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) return type;

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName))
            type = NETWORK_TYPE_WIFI;
        else if ("MOBILE".equalsIgnoreCase(typeName))
            type = TextUtils.isEmpty(android.net.Proxy.getDefaultHost()) ?
                    (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
        else
            type = NETWORK_TYPE_UNKNOWN;
    }
    return type;
}
 
开发者ID:Jusenr,项目名称:androidtools,代码行数:25,代码来源:NetworkUtils.java

示例7: getNetworkTypeName

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    }

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
                    : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:23,代码来源:Kits.java

示例8: getNetworkTypeName

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * Get network type name
 * 
 * @param context
 * @return
 */
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    };

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
                    : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
 
开发者ID:harrylefit,项目名称:EazyBaseMVP,代码行数:29,代码来源:NetWorkUtils.java

示例9: getNetworkTypeName

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    }

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            //String proxyHost = android.net.Proxy.getDefaultHost();//deprecated
            String proxyHost = System.getProperty("http.proxyHost");
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G) : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:23,代码来源:NetUtils.java

示例10: getNetworkType

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String getNetworkType(Context context) {
    String networkType = EnvironmentCompat.MEDIA_UNKNOWN;
    if (context == null) {
        LOG.w(TAG, "get network type failed(null context)");
        return networkType;
    }
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService("connectivity");
    if (connMgr == null) {
        LOG.e(TAG, "get connectivity manager failed");
        return networkType;
    }
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        return networkType;
    }
    String typeName = networkInfo.getTypeName();
    String subTypeName = networkInfo.getSubtypeName();
    String extraInfo = networkInfo.getExtraInfo();
    if (TextUtils.isEmpty(subTypeName)) {
        networkType = typeName + "/" + extraInfo;
    } else {
        networkType = typeName + "(" + subTypeName + ")/" + extraInfo;
    }
    return networkType;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:26,代码来源:SystemUtils.java

示例11: e

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String e(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
            ("connectivity");
    if (connectivityManager == null) {
        return "MOBILE";
    }
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo != null) {
        return activeNetworkInfo.getTypeName();
    }
    return "MOBILE";
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:a.java

示例12: a

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static HttpHost a(Context context) {
    if (context == null) {
        return null;
    }
    try {
        if (context.getPackageManager().checkPermission("android.permission" +
                ".ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
            return null;
        }
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
                ("connectivity")).getActiveNetworkInfo();
        if (activeNetworkInfo == null) {
            return null;
        }
        if (activeNetworkInfo.getTypeName() != null && activeNetworkInfo.getTypeName()
                .equalsIgnoreCase("WIFI")) {
            return null;
        }
        String extraInfo = activeNetworkInfo.getExtraInfo();
        if (extraInfo == null) {
            return null;
        }
        if (extraInfo.equals("cmwap") || extraInfo.equals("3gwap") || extraInfo.equals
                ("uniwap")) {
            return new HttpHost(Network.CMWAP_GATEWAY, 80);
        }
        if (extraInfo.equals("ctwap")) {
            return new HttpHost("10.0.0.200", 80);
        }
        return null;
    } catch (Object th) {
        f.e(th);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:35,代码来源:k.java

示例13: onReceive

import android.net.NetworkInfo; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    long time = System.currentTimeMillis();
    if (time - oldTime < 1000) {
        return;
    }
    oldTime = time;
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isAvailable()) {
        switch (netInfo.getType()) {
            case ConnectivityManager.TYPE_MOBILE:
                netType = 0;
                netName = netInfo.getSubtypeName();
                break;
            case ConnectivityManager.TYPE_WIFI:
                netType = 1;
                netName = netInfo.getTypeName();
                break;
            case ConnectivityManager.TYPE_ETHERNET:
                netType = 2;
                netName = netInfo.getTypeName();
                break;
            default:
                netType = 3;
                netName = "OtherNetWork";
                break;
        }
    } else {
        netType = -1;
        netName = "NoNetWork";
    }
    if (onNetListener != null) {
        onNetListener.onNetStatus(netType, netName);
    }
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:39,代码来源:NetBroadcastReceiver.java

示例14: getNetWorkType

import android.net.NetworkInfo; //导入方法依赖的package包/类
/**
 * 网络
 */
public static void getNetWorkType(Context context, OnNetStatusListener listener) {
    int netType;
    String netName;
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isAvailable()) {
        switch (netInfo.getType()) {
            case ConnectivityManager.TYPE_MOBILE:
                netType = 0;
                netName = netInfo.getSubtypeName();
                break;
            case ConnectivityManager.TYPE_WIFI:
                netType = 1;
                netName = netInfo.getTypeName();
                break;
            case ConnectivityManager.TYPE_ETHERNET:
                netType = 2;
                netName = netInfo.getTypeName();
                break;
            default:
                netType = 3;
                netName = "OtherNetWork";
                break;
        }
    } else {
        netType = -1;
        netName = "NoNetWork";
    }
    listener.onNetStatus(netType, netName);
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:35,代码来源:AndroidUtils.java

示例15: E

import android.net.NetworkInfo; //导入方法依赖的package包/类
public static String E(Context context) {
    String str = "";
    try {
        if (r.a(context, "android.permission.INTERNET") && r.a(context, "android.permission" +
                ".ACCESS_NETWORK_STATE")) {
            String typeName;
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService
                    ("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
                typeName = activeNetworkInfo.getTypeName();
                String extraInfo = activeNetworkInfo.getExtraInfo();
                if (typeName != null) {
                    if (typeName.equalsIgnoreCase("WIFI")) {
                        return "WIFI";
                    }
                    if (typeName.equalsIgnoreCase("MOBILE")) {
                        return extraInfo != null ? extraInfo : "MOBILE";
                    } else {
                        if (extraInfo != null) {
                            return extraInfo;
                        }
                        return typeName;
                    }
                }
            }
            typeName = str;
            return typeName;
        }
        cT.d("can not get the permission of android.permission.ACCESS_WIFI_STATE");
        return str;
    } catch (Throwable th) {
        cT.b(th);
        return str;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:36,代码来源:l.java


注:本文中的android.net.NetworkInfo.getTypeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。