MobileUtil.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:letv 作者:
public static String getNetType(Context context) {
    String type = "network";
    if (context == null) {
        return type;
    }
    try {
        NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        if (networkInfo == null || !networkInfo.isAvailable()) {
            return "nont";
        }
        if (1 == networkInfo.getType()) {
            return "wifi";
        }
        switch (((TelephonyManager) context.getSystemService("phone")).getNetworkType()) {
            case 1:
            case 2:
            case 4:
                return "2g";
            case 13:
                return "4g";
            default:
                return "3g";
        }
    } catch (Exception e) {
        e.printStackTrace();
        return type;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号