zoukankan      html  css  js  c++  java
  • Android获取网络类型

    public static final String NETWORK_CLASS_UNKNOWN = "unknown";
    public static final String NETWORK_CLASS_WIFI = "wifi";
    public static final String NETWORK_CLASS_2_G = "2g";
    public static final String NETWORK_CLASS_3_G = "3g";
    public static final String NETWORK_CLASS_4_G = "4g";

    /**
    * 获取网络类型
    * @param context
    * @return
    */
    public static String getNetworkType(Context context) {

    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();

    if (info != null) {

    switch (info.getType()) {
    case ConnectivityManager.TYPE_WIFI:
    return NETWORK_CLASS_WIFI;
    case ConnectivityManager.TYPE_MOBILE:
    switch (info.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_GPRS:
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    return NETWORK_CLASS_2_G;
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    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:
    return NETWORK_CLASS_3_G;
    case TelephonyManager.NETWORK_TYPE_LTE:
    return NETWORK_CLASS_4_G;
    default:
    return NETWORK_CLASS_UNKNOWN;
    }
    default:
    return NETWORK_CLASS_UNKNOWN;
    }
    }

    return NETWORK_CLASS_UNKNOWN;
    }

  • 相关阅读:
    jqueryUI弹出框问题
    spring data jpa分页
    解决eclipse编辑js和html卡的问题
    web.xml添加编码过滤器
    Apache SolrCloud安装
    搭建zookeeper集群
    html页面读取PDF小案例
    .NET 使用Process调用7_zip解压文件
    .NET 中三种正确的单例写法
    Git 笔记
  • 原文地址:https://www.cnblogs.com/zfg-technology/p/4900467.html
Copyright © 2011-2022 走看看