1、首先我们需要知道手机IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。那么第一步就是先获取手机IMSI号码:代码如下
2、TelephonyManager telMgr = (TelephonyManager) conte旌忭檀挢xt.getSystemService(Context.TELEPHONY_SERVICE);Stringimei = telMgr.getDeviceId();
3、然后整个代码连起来就是这样的:
4、/*** 返回用户手机运营商名称 * @param telephonyManager * @return*/public String g髫潋啜缅etProvidersName(TelephonyManager telephonyManager) {String ProvidersName = null;telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);String IMSI; // 返回唯一的用户ID;就是这张卡的编号神马的IMSI = telephonyManager.getSubscriberId();if (IMSI == null)return "unkwon";// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。其中if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) { ProvidersName = "中国移动"; } else if (IMSI.startsWith("46001")) { ProvidersName ="中国联通"; } else if (IMSI.startsWith("46003")) { ProvidersName = "中国电信"; }try { ProvidersName = URLEncoder.encode("" + ProvidersName, "UTF-8");} catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace();} return ProvidersName;}