當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。