Android获取SIM卡信息 & TelephonyManager的介绍

Android 获取sim卡运营商信息

TelephonyManager的介绍:

Provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information. Applications can also register a listener to receive notification of telephony state changes.

译: 提供设备上获取通讯服务信息的入口应用程序可以使用这个类中的方法来确定电话服务和状态,以及访问某些类型的用户信息。应用程序也可以注册一个监听器来接收通知的电话状态改变。

You do not instantiate this class directly; instead, you retrieve a reference to an instance through {@link android.content.Context#getSystemService Context.getSystemService(Context.TELEPHONY_SERVICE)}.

译: 你不能直接实例化这个类;相反,您检索引用一个实例通过{ @link android.content.Context # getSystemService Context.getSystemService(Context.TELEPHONY_SERVICE)}。

Note that access to some telephony information is permission-protected. Your application cannot access the protected information unless it has the appropriate permissions declared in its manifest file. Where permissions apply, they are noted in the the methods through which you access the protected information.

译:注意,访问某些permission-protected电话信息。您的应用程序不能访问受保护的信息,除非有适当的权限声明的清单文件。权限申请,他们在你访问受保护信息的方法。

简单总结:
     1.TelephonyManager类是用来提供获取设备通讯服务信息的入口,也可注册监听器来监听电话状态的改变。

     2.不能直接实例化这个类,可通过以下方法使用 TelephonyManager tm = (TelephonyManager)Context.getSystemService(Context.TELEPHONY_SERVICE); 

       3.必须要声明权限。


 
/*IMSI:国际移动用户识别码(唯一标识),IMSI = MCC + MNC + MSIN,其中MCC是指移动台国家代码(3 位,中国460),MNC是指移动网代码(2 位中国00),MSIN是指移动用户识别号码(10 位 )。
  IMSI共有15位,其结构如下:
  MCC+MNC+MSIN ,(MNC+MSIN=NMSI)
  MCC:Mobile Country Code,移动国家码,MCC的资源由国际电联(ITU)统一分配和管理,唯一识别移动用户所属的国家,共3位,中国为460;
  MNC:Mobile Network Code,移动网络码,共2位,中国移动TD系统使用00,中国联通GSM系统使用01,中国移动GSM系统使用02,中国电信CDMA系统使用03,一个典型的IMSI号码为460030912121001;
  MSIN:Mobile Subscriber Identification Number共有10位,其结构如下:
  09+M0M1M2M3+ABCD
  其中的M0M1M2M3和MDN号码中的H0H1H2H3可存在对应关系,ABCD四位为自由分配。
  可以看出IMSI在MSIN号码前加了MCC即NMSI,可以区别出每个用户的来自的国家,因此可以实现国际漫游。在同一个国家内,如果有多个移动网络运营商,可以通过MNC来进行区别.*/

     
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
                // 第一种方法
                String imsi = tm.getSubscriberId();
                if (imsi != null) {
                        if (imsi.startsWith("46000") || imsi.startsWith("46002")) {
                                // 中国移动
                        }else if (imsi.startsWith("46001")) {
                                // 中国联通
                        }else if (imsi.startsWith("46003")) {
                                // 中国电信
                        }
                }
        
                // 第二种方法
                String operator = tm.getSimOperator();
                if (operator != null) {
                        if (operator.startsWith("46000") || operator.startsWith("46002")) {
                                // 中国移动
                        }else if (operator.startsWith("46001")) {
                                // 中国联通
                        }else if (operator.startsWith("46003")) {
                                // 中国电信
                        }
                }


主要方法及说明:
getSimOperatorName();  // Returns the Service Provider Name (SPN). 获取服务提供商名字,比如电信,联通,移动 用下面的方法 第一种方法: 获取手机的IMSI码,并判断是中国移动/中国联通/中国电信

getDeviceId(); // 返回的IMEI / MEID的设备。 如果该设备是GSM设备 然后IMEI号将被退回,如果该设备是一个CDMA设备然后MEID 将被退回 

getCellLocation(); // 返回的单元格位置的装置 ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION.

getNetworkOperator(); // 返回的MCC +跨国公司的注册网络运营商

getNetworkOperatorName(); // 返回注册的网络运营商的名字

getLine1Number(); //  返回设备的电话号码(MSISDN号码)

getNetworkCountryIso(); // 返回注册的网络运营商的国家代码,例如中国为cn。

getSimCountryIso(); // 返回SIM卡运营商的国家代码 

getSimSerialNumber(); // 返回SIM卡的序列号(装有SIM卡的获取方法),如果没SIM卡要获取序列号: String serialNum = android.os.Build.SERIAL;  

getPhoneType(); // 获取移动终端类型

getNetworkType(); //  返回网络设备可用的类型。代表4G的值:NETWORK_TYPE_LTE = 13;



当然了,别忘了加上权限:
< uses-permission android:name = "android.permission.READ_PHONE_STATE" />
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值