Android中判断用户运营商是移动联通还是电信

2025-11-17 07:20:14

1、首先我们需要知道手机IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。那么第一步就是先获取手机IMSI号码:代码如下

2、TelephonyManager telMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

String imei = telMgr.getDeviceId();

3、然后整个代码连起来就是这样的:

4、/**

 * 返回用户手机运营商名称  * @param telephonyManager  * @return

*/

 public String getProvidersName(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;

}

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢