获取手机设备各种信息

import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.TimeZone;
import com.appwoo.mdm.library.entity.Models;
import com.txtw.base.utils.ReflectUtil;
import com.txtw.base.utils.StringUtil;
import com.txtw.base.utils.httputil.ConstantSharedPreference;
import android.app.Service;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.WindowManager;


public class PhoneInfoUtil {


    /**
     * 获取设备号
     *
     * @param context
     * @return
     */
    public static String getDeviceID(Context context) {
        
       
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
      
               retrun tm.getDeviceId().toUpperCase();
    }
    

    /**
     * 获取ip地址
     */
    public static String getLocalIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface
                    .getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf
                        .getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        return inetAddress.getHostAddress().toString();
                    }
                }
            }
        } catch (SocketException ex) {
            ex.printStackTrace();
        }

        return "";
    }

    /**
     * 获取手机序列号ID
     *
     * @param context
     * @return
     */
    public static String getUniqueID(Context context) {
        // 1 compute IMEI
        TelephonyManager TelephonyMgr = (TelephonyManager) context
                .getSystemService(context.TELEPHONY_SERVICE);
        String m_szImei = TelephonyMgr.getDeviceId(); // Requires
                                                        // READ_PHONE_STATE
        // 2 compute DEVICE ID
        String m_szDevIDShort = "35"
                + // we make this look like a valid IMEI
                Build.BOARD.length() % 10 + Build.BRAND.length() % 10
                + Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10
                + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
                + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10
                + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10
                + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
                + Build.USER.length() % 10; // 13
                                            // digits
        // 3 android ID - unreliable
        String m_szAndroidID = Secure.getString(context.getContentResolver(),
                Secure.ANDROID_ID);

        // 4 wifi manager, read MAC address - requires
        // android.permission.ACCESS_WIFI_STATE or comes as null
        WifiManager wm = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
        // 5 Bluetooth MAC address android.permission.BLUETOOTH required
        // BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth
        // adapter
        String m_szBTMAC = "";
        try {
            Object m_BluetoothAdapter = ReflectUtil.invoke(
                    Class.forName("android.bluetooth.BluetoothAdapter"), null,
                    "getDefaultAdapter", new Class[] {}, new Object[] {});
            // m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (m_BluetoothAdapter != null) {
                m_szBTMAC = (String) ReflectUtil.invoke(m_BluetoothAdapter,
                        "getAddress", new Class[] {}, new Object[] {});
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // 6 SUM THE IDs
        String m_szLongID = m_szImei + m_szDevIDShort + m_szAndroidID
                + m_szWLANMAC + m_szBTMAC;
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        m.update(m_szLongID.getBytes(), 0, m_szLongID.length());
        byte p_md5Data[] = m.digest();
        String m_szUniqueID = new String();
        for (int i = 0; i < p_md5Data.length; i++) {
            int b = (0xFF & p_md5Data[i]);
            // if it is a single digit, make sure it have 0 in front (proper
            // padding)
            if (b <= 0xF)
                m_szUniqueID += "0";
            // add number to string
            m_szUniqueID += Integer.toHexString(b);
        }
        m_szUniqueID = m_szUniqueID.toUpperCase().length() >= 32 ? m_szUniqueID
                .toUpperCase().substring(16) : m_szUniqueID.toUpperCase();
        return m_szUniqueID;
    }

    public static String calculateParityBit(String meid) {

        if (!checkMeid(meid)) {
            return "-1";
        }
        if (isHexMeid(meid)) {
            return calculateParityBit(meid, 16);

        } else {
            return calculateParityBit(meid, 10);
        }

    }

    public static boolean isHexMeid(String meid) {
        // TODO Auto-generated method stub
        if (meid.charAt(0) < 0x41) {
            return false;
        }
        return true;
    }

    public static boolean checkMeid(String meid) {

        if (null == meid || (14 != meid.length())) {
            return false;
        }
        for (int i = 0; i < meid.length(); i++) {
            char tmp = meid.charAt(i);
            if (!(0x30 <= tmp && tmp <= 0x39) && !(0x41 <= tmp && tmp <= 0x46)
                    && !(0x61 <= tmp && tmp <= 0x66)) {
                return false;
            }
        }
        return true;
    }

    public static String calculateParityBit(String meid, int radix) {
        if (!checkMeid(meid)) {
            return "0";
        }
        int[] odd_parity = get_odd_parity(meid, radix);
        int res = 0;
        int tmp = 0;
        for (int i = 0, count = 0; i < meid.length(); i = i + 2, count++) {
            try {
                tmp = Integer.valueOf(meid.substring(i, i + 1), radix)
                        .intValue();
            } catch (NumberFormatException e) {
                tmp = 0;
            }
            res = res + tmp + odd_parity[count] / radix + odd_parity[count]
                    % radix;
        }
        if (0 == res % radix) {
            return "0";
        } else {
            return Integer.toHexString(radix - (res % radix));
        }
    }

    public static int[] get_odd_parity(String meid, int radix) {

        int[] odd_parity_array = new int[meid.length() / 2];
        int count = 0;
        int tmp = 0;
        for (int i = 1; i < meid.length(); i = i + 2, count++) {
            try {
                tmp = Integer.valueOf(meid.substring(i, i + 1), radix)
                        .intValue();
            } catch (NumberFormatException e) {
                tmp = 0;
            }
            odd_parity_array[count] = tmp * 2;
        }
        return odd_parity_array;
    }

    /**
     * 判断sim卡是否存在
     *
     * @param mContext
     * @return
     */
    public static boolean isSimExist(Context mContext) {
        TelephonyManager mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
          int simState = mTelephonyManager.getSimState();
          boolean exist = simState == TelephonyManager.SIM_STATE_READY;
          if(!exist){
              if(Models.isModel(Models.ZTEB880)){
                  int networkType = mTelephonyManager.getNetworkType();
                  if(networkType == TelephonyManager.NETWORK_TYPE_EDGE){
                      exist = true;
                  }
              }
          }
          
          return exist;
    }

    /**
     * 获取手机号吗
     *
     * @param context
     * @return
     */
    public static String getPhoneNumber(Context context) {
        TelephonyManager mTelephonyMgr;
        mTelephonyMgr = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        return mTelephonyMgr.getLine1Number();
    }

    
    /**
     * 获取IMSI
     *
     * @param context
     * @return
     * @throws com.appwoo.txtw.util.PhoneInfoUtil.IvalidImsiException
     */
    public static String getImsi(Context context) throws IvalidImsiException {

        String imsi="";
        TelephonyManager tpm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        imsi = tpm.getSubscriberId();
        System.out.println("imsi============================" + imsi);
        if (StringUtil.isEmpty(imsi) || imsi.length() < 15)
            throw new IvalidImsiException();

        return imsi;
    }
    
    /**
     * 无效的imsi值
     *
     */
    public static class IvalidImsiException extends Exception {

        private static final long serialVersionUID = 1L;
    }
    
    /**
     * 获取手机型号信息,例如mode={lenovo,A820};
     * @param context
     * @return
     */
    public static String getPhoneModeInfo(){
        return Build.MODEL;
    }
    
    public static boolean getSimState(Context ctx) {
        if (Build.MODEL.equals("HUAWEI P6-C00")) {//返回的imsi为""; getSimState 一直返回TelephonyManager.SIM_STATE_UNKNOWN
            return PhoneInfoUtil.getPhoneNumber(ctx) != null;
        }
        return PhoneInfoUtil.isSimExist(ctx);
    }
    
    /**
     * 操作系统
     */
    public static String getSystemName(){
        return "android";
    }
    
    /**
     * 获取手机操作系统版本
     * @return
     */
      public static String getTelSdk()
      {
         return "android" + Build.VERSION.RELEASE;
      }
      
      /**
       * 手机SDK,即API level
       */
      public static String getSDK(){
          return Build.VERSION.SDK;
      }
      
      /**
       * sdk >=15  4.0版本以上  
       * @return
       */
      public static boolean getSDK15()
      {
            return Integer.valueOf(Build.VERSION.SDK) >= 15;
      }
      
      /**
       * 手机制造商
       */
      public static String getManufacturer(){
          return Build.MANUFACTURER;
      }
      
      /**
       * 处理器
       * /proc/cpuinfo文件中第一行是CPU的型号,第二行是CPU的频率(单位KHz),可以通过读文件,读取这些数据!
       */
      public static String[] getCpuInfo() {  
            String str1 = "/proc/cpuinfo";  
            String str2="";  
            String[] cpuInfo={"",""};  
            String[] arrayOfString;  
            try {  
                FileReader fr = new FileReader(str1);  
                BufferedReader localBufferedReader = new BufferedReader(fr, 8192);  
                str2 = localBufferedReader.readLine();  
                arrayOfString = str2.split("\\s+");  
                for (int i = 2; i < arrayOfString.length; i++) {  
                    cpuInfo[0] = cpuInfo[0] + arrayOfString[i] + " ";  
                }  
                str2 = localBufferedReader.readLine();  
                arrayOfString = str2.split("\\s+");  
                cpuInfo[1] += arrayOfString[2];  
                localBufferedReader.close();  
            } catch (IOException e) {  
            }  
            return cpuInfo;  
        }  

     

// 获取CPU最大频率(单位KHZ)

     // "/system/bin/cat" 命令行

     // "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存储最大频率的文件的路径

        public static String getMaxCpuFreq() {
                String result = "";
                ProcessBuilder cmd;
                try {
                        String[] args = { "/system/bin/cat",
                                        "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };
                        cmd = new ProcessBuilder(args);
                        Process process = cmd.start();
                        InputStream in = process.getInputStream();
                        byte[] re = new byte[24];
                        while (in.read(re) != -1) {
                                result = result + new String(re);
                        }
                        in.close();
                } catch (IOException ex) {
                        ex.printStackTrace();
                        result = "N/A";
                }
                return result.trim();
        }

      /**
       * 处理器核数
       */
      public static int getNumberOfCPUCores() {
          if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            // Gingerbread doesn't support giving a single application access to both cores, but a
            // handful of devices (Atrix 4G and Droid X2 for example) were released with a dual-core
            // chipset and Gingerbread; that can let an app in the background run without impacting
            // the foreground application. But for our purposes, it makes them single core.
            return 1;
          }
          int cores;
          try {
            cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
          } catch (SecurityException e) {
            cores = 0;
          } catch (NullPointerException e) {
            cores = 0;
          }
          return cores;
        }
        
        private static final FileFilter CPU_FILTER = new FileFilter() {
          @Override
          public boolean accept(File pathname) {
            String path = pathname.getName();
            //regex is slow, so checking char by char.
            if (path.startsWith("cpu")) {
              for (int i = 3; i < path.length(); i++) {
                if (path.charAt(i) < '0' || path.charAt(i) > '9') {
                  return false;
                }
              }
              return true;
            }
            return false;
          }
        };
      
      /**
       * ROM大小
       * [0]为总大小,[1]为可用大小
       */
        public static long[] getRomMemroy() {  
            long[] romInfo = new long[2];  
            //Total rom memory  
            romInfo[0] = getTotalInternalMemorySize();  
      
            //Available rom memory  
            File path = Environment.getDataDirectory();  
            StatFs stat = new StatFs(path.getPath());  
            long blockSize = stat.getBlockSize();  
            long availableBlocks = stat.getAvailableBlocks();  
            romInfo[1] = blockSize * availableBlocks;  
//            getVersion();  
            return romInfo;  
        }
        
        public static long getTotalInternalMemorySize() {  
            File path = Environment.getDataDirectory();  
            StatFs stat = new StatFs(path.getPath());  
            long blockSize = stat.getBlockSize();  
            long totalBlocks = stat.getBlockCount();  
            return totalBlocks * blockSize;  
        }
      
        /**
         * SD卡大小
         * [0]为总大小,[1]为可用大小
         */
        public static long[] getSDCardMemory() {  
            long[] sdCardInfo=new long[2];  
            String state = Environment.getExternalStorageState();  
            if (Environment.MEDIA_MOUNTED.equals(state)) {  
                File sdcardDir = Environment.getExternalStorageDirectory();  
                StatFs sf = new StatFs(sdcardDir.getPath());  
                long bSize = sf.getBlockSize();  
                long bCount = sf.getBlockCount();  
                long availBlocks = sf.getAvailableBlocks();  
      
                sdCardInfo[0] = bSize * bCount;//总大小  
                sdCardInfo[1] = bSize * availBlocks;//可用大小  
            }  
            return sdCardInfo;  
        }

        /**
         *获取RAM总大小
         */
        public static long getTotalMemory(Context context){
            String str1 = "/proc/meminfo";// 系统内存信息文件
            String str2;
            String[] arrayOfString;
            long initial_memory = 0;
            try {
                FileReader localFileReader = new FileReader(str1);
                BufferedReader localBufferedReader = new BufferedReader(
                localFileReader, 8192);
                str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小
                arrayOfString = str2.split("\\s+");
//                for (String num : arrayOfString) {
//                    Log.i(str2, num + "\t");
//                }
                initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte
                localBufferedReader.close();
            } catch (IOException e) {
                }
                //return Formatter.formatFileSize(context, initial_memory);// Byte转换为KB或者MB,内存大小规格化
                System.out.println("总运存---$amp;>amp;>amp;>amp;$quot;"+initial_memory/(1024*1024));
                return initial_memory/(1024*1024);
        }

        /**
         * 屏幕分辨率
         */
         public static String getScreenResolution(Context context){
            //创建对象
            DisplayMetrics mDisplayMetrics = new DisplayMetrics();
            //获取界面管理者
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            //将当前窗口的一些信息放在DisplayMetrics类中
            wm.getDefaultDisplay().getMetrics(mDisplayMetrics);
            //读取长宽
            int W = mDisplayMetrics.widthPixels;
            int H = mDisplayMetrics.heightPixels;
            return W+"*"+H;
         }

        /**
         * 手机语言环境
         */
        public static String getLanguage(Context context){
            Locale locale = context.getResources().getConfiguration().locale;
            String language = locale.getLanguage();
            return language;
        }

        /**
         * 时区
         */
         public static String getTimezone(){
            TimeZone tz = TimeZone.getDefault();  
            String s = tz.getDisplayName(false, TimeZone.SHORT)+" " +tz.getID();
            return s;
         }


        
        /**
         * 开机时间
         */
        public static String getTimes() {  
            long ut = SystemClock.elapsedRealtime() / 1000;  
            if (ut == 0) {  
                ut = 1;  
            }  
            int m = (int) ((ut / 60) % 60);  
            int h = (int) ((ut / 3600));  
            return h + "小时" + m + "分钟" ;  
        }
        
        /**
         * 内核版本
         */
        public static String getLinuxCore_Ver() {  
            Process process = null;  
            String kernelVersion = "";  
            try {  
                process = Runtime.getRuntime().exec("cat /proc/version");  
            } catch (IOException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
            }
            // get the output line  
            InputStream outs = process.getInputStream();  
            InputStreamReader isrout = new InputStreamReader(outs);  
            BufferedReader brout = new BufferedReader(isrout, 8 * 1024);  
              
              
            String result = "";  
            String line;  
            // get the whole standard output string  
            try {  
            while ((line = brout.readLine()) != null) {  
            result += line;  
            }  
            } catch (IOException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
            }  
              
              
            try {  
            if (result != "") {  
            String Keyword = "version ";  
            int index = result.indexOf(Keyword);  
            line = result.substring(index + Keyword.length());  
            index = line.indexOf(" ");  
            kernelVersion = line.substring(0, index);  
            }  
            } catch (IndexOutOfBoundsException e) {  
            e.printStackTrace();  
            }  
            return kernelVersion;             
        }
        
        /**
          * 基带版本
          */            
        public static String getBaseband_Ver(){  
            String Version = "";  
            try {  
                Class cl = Class.forName("android.os.SystemProperties");  
                Object invoker = cl.newInstance();  
                Method m = cl.getMethod("get", new Class[] { String.class,String.class });  
                Object result = m.invoke(invoker, new Object[]{"gsm.version.baseband", "no message"});    
                Version = (String)result;  
            } catch (Exception e) {  
                e.printStackTrace();
            }  
            return Version;  
        }  
        
        /**
         * 内部版本
         * @return
         */
        public static String getInner_Ver(){  
            String ver = "" ;               
            if(android.os.Build.DISPLAY .contains(android.os.Build.VERSION.INCREMENTAL)){  
                ver = android.os.Build.DISPLAY;  
            }else{  
                ver = android.os.Build.VERSION.INCREMENTAL;  
            }  
            return ver;                
        }
        
      /**
       * 格式化数据方法
       */
      public String formatSize(long size) {  
            String suffix = null;  
            float fSize=0;  
          
            if (size >= 1024) {  
                suffix = "KB";  
                fSize=size / 1024;  
                if (fSize >= 1024) {  
                    suffix = "MB";  
                    fSize /= 1024;  
                }  
                if (fSize >= 1024) {  
                    suffix = "GB";  
                    fSize /= 1024;  
                }  
            } else {  
                fSize = size;  
            }  
            java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");  
            StringBuilder resultBuffer = new StringBuilder(df.format(fSize));  
            if (suffix != null)  
                resultBuffer.append(suffix);  
            return resultBuffer.toString();      
      }
      
      /**
       * ICCID,集成电路卡识别码(固化在手机SIM卡中) ICCID为IC卡的唯一识别号码
       */
      public static String getICCID(Context context){
          TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);  
          return tm.getSimSerialNumber();
      }
      
      
      
      /**
       * 是否漫游
       */
      public static String getIsRoam(Context context){
          TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);  
          return tm.isNetworkRoaming()?"是":"否";
      }
      
      /**
       * 网络类型
       *
       */
     

/**
      * 网络类型
      * 
      */
  //没有连接
  public static final String NETWORN_NONE = "无网络连接";
  //wifi连接
  public static final String NETWORN_WIFI = "wifi";
//手机网络数据连接
public static final String NETWORN_2G = "2G";
public static final String NETWORN_3G = "3G";
public static final String NETWORN_4G = "4G";
public static final String NETWORK_TYPE_UNKNOWN = "未知";  //0
public static final String NETWORK_TYPE_GPRS = "GPRS";   //1
public static final String NETWORK_TYPE_EDGE = "EDGE";   //2
public static final String NETWORK_TYPE_UMTS = "UMTS";   //3
public static final String NETWORK_TYPE_CDMA = "CDMA(IS95A or IS95B)";//4
public static final String NETWORK_TYPE_EVDO_0 = "EVDO(revision 0)";// 5
public static final String NETWORK_TYPE_EVDO_A = "EVDO(revision A)";//  6
public static final String NETWORK_TYPE_1xRTT = "1xRTT";//  7
public static final String NETWORK_TYPE_HSDPA = "HSDPA";   // 8
public static final String NETWORK_TYPE_HSUPA = "HSUPA";   //9
public static final String NETWORK_TYPE_HSPA = "HSPA";//10
public static final String NETWORK_TYPE_IDEN = "iDen";//11
public static final String NETWORK_TYPE_EVDO_B = "EVDO(revision B)";//12
public static final String NETWORK_TYPE_LTE = "LTE";//13
public static final String NETWORK_TYPE_EHRPD = "eHRPD";//14
public static final String NETWORK_TYPE_HSPAP = "HSPA+";//15
public static final String NETWORK_TYPE_GSM = "GSM";//16

public static String getNetworkType(Context context){
     ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   //是否有连接
     if (null == connManager){
        return NETWORN_NONE;
     }
   //是否有网络
     NetworkInfo activeNetInfo = connManager.getActiveNetworkInfo();
     if (activeNetInfo == null || !activeNetInfo.isAvailable()) {
        return NETWORN_NONE;
     }
     // 是否是Wifi
     NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
     if(null!=wifiInfo){
        NetworkInfo.State state = wifiInfo.getState();
        if(null!=state)
           if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) {
              return NETWORN_WIFI;
           }
     }
     // 是否是移动网络
     NetworkInfo networkInfo=connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
     if(null!=networkInfo){
        NetworkInfo.State state = networkInfo.getState();
        String strSubTypeName = networkInfo.getSubtypeName();
        if(null!=state)
           if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) {
              switch (activeNetInfo.getSubtype()) {
                 case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                    return NETWORK_TYPE_UNKNOWN;
                 case TelephonyManager.NETWORK_TYPE_GPRS: // 联通2g
                     return NETWORK_TYPE_GPRS;
                 case TelephonyManager.NETWORK_TYPE_EDGE: // 移动2g
                    return NETWORK_TYPE_EDGE;
                 case TelephonyManager.NETWORK_TYPE_UMTS:
                    return NETWORK_TYPE_UMTS;
                 case TelephonyManager.NETWORK_TYPE_CDMA: // 电信2g
                    return NETWORK_TYPE_CDMA;
                 case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return NETWORK_TYPE_EVDO_0;
                 case TelephonyManager.NETWORK_TYPE_EVDO_A: // 电信3g
                    return NETWORK_TYPE_EVDO_A;
                 case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return NETWORK_TYPE_1xRTT;
                 case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return NETWORK_TYPE_HSDPA;
                 case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return NETWORK_TYPE_HSUPA;
                 case TelephonyManager.NETWORK_TYPE_HSPA:
                    return NETWORK_TYPE_HSPA;
                 case TelephonyManager.NETWORK_TYPE_IDEN:
                    return NETWORK_TYPE_IDEN;
                 case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    return NETWORK_TYPE_EVDO_B;
                 case TelephonyManager.NETWORK_TYPE_LTE:
                    return NETWORK_TYPE_LTE;
                 case TelephonyManager.NETWORK_TYPE_EHRPD:
                    return NETWORK_TYPE_EHRPD;
                 case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return NETWORK_TYPE_HSPAP;
                 default://有机型返回16,17
                    //中国移动 联通 电信 三种3G制式
                    if (strSubTypeName.equalsIgnoreCase("TD-SCDMA")
                          || strSubTypeName.equalsIgnoreCase("WCDMA")
                          || strSubTypeName.equalsIgnoreCase("CDMA2000")){
                       return NETWORN_3G;
                    }else{
                       return NETWORK_TYPE_UNKNOWN;
                    }
              }
           }
     }
     return NETWORN_NONE;
     }


      
      /**
       * SIM卡运营商
       */
      public static String getSIMOperatorName(Context context){
          TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);

 
String simOperator = ""; String imsi = tm.getSubscriberId(); if (imsi != null) { if (imsi.startsWith("46000") || imsi.startsWith("46002")){ //因为移动网络编号46000下的IMSI已经用完,所以虚拟了一个46002编号,134/159号段使用了此编号 //中国移动  simOperator = "中国移动";  } else if (imsi.startsWith("46001")) {//中国联通  simOperator = "中国联通";  } else if (imsi.startsWith("46003")) { //中国电信  simOperator = "中国电信";  } }else{ simOperator = "无SIM卡"; } return simOperator;

      }

      
}

发布了12 篇原创文章 · 获赞 4 · 访问量 9616

猜你喜欢

转载自blog.csdn.net/lhy24680/article/details/51758854