• Android 获取网络类型(WIFI、CMNET、CMWAP)


    下面这个方法用于获取系统当前网络类型:

       1: public static int getNetworkType(Context context) {
       2:         ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
       3:         
       4:         if (connectivity != null) { 
       5:             // 获取网络连接管理的对象
       6:             NetworkInfo info = connectivity.getActiveNetworkInfo();
       7:  
       8:             if (info != null && info.isConnected()) {
       9:                 // 判断当前网络是否已经连接
      10:                 if (info.getState() == NetworkInfo.State.CONNECTED) {
      11:                     if (info.getTypeName().equals("WIFI")) {
      12:                         return MrDefines.NETTYPE_WIFI;
      13:                     } else {
      14:                         Cursor mCursor = context.getContentResolver().query(Uri.parse("content://telephony/carriers"), 
      15:                                 new String[] {"name"}, "current=1", null, null);
      16:                         
      17:                         if(mCursor != null && mCursor.moveToFirst()){
      18:                             String name = mCursor.getString(0);
      19:                             
      20:                             if(name.equalsIgnoreCase("cmnet"))
      21:                                 return MrDefines.NETTYPE_CMNET;
      22:                             else if(name.equalsIgnoreCase("cmwap"))
      23:                                 return MrDefines.NETTYPE_CMWAP;
      24:                         }
      25:                     }
      26:                 }
      27:             }
      28:         }
      29:         
      30:         return MrDefines.NETTYPE_UNKNOW;
      31:     }
       1: public static final int NETTYPE_WIFI=0,
       2:         NETTYPE_CMWAP=1,
       3:         NETTYPE_CMNET=2,
       4:         NETTYPE_UNKNOW=3;
  • 相关阅读:
    gojs入门
    chartjs:改变图表的外观
    chart.js入门
    verilog与C语言的6点重大区别
    PCB布线原则【转】_神经火光_百度空间
    verilog中对同一个变量有判断条件的赋值
    同步复位与异步复位——异步复位同步释放
    如何利用TCL文件给FPGA分配引脚
    0欧姆电阻的作用
    独热码
  • 原文地址:https://www.cnblogs.com/yichouangle/p/2780037.html
Copyright © 2020-2023  润新知