Android中TelephonyMnager的使用

TelephonyMnager的工作以及获取手机信息所需要的权限

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
//获取TelephonyMnager对象

TelephonyManager  tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

//获取设备id

String deviceId = tm.getDeviceId();

//获取SIM卡序列号

String SIMSerialNumber=tm.getSimSerialNumber();

//获得网络国家ISO编码

String networkCountryISO=tm.getNetworkCountryIso();

//获取SIM国家ISO代码
String SIMCountryISO=tm.getSimCountryIso();

//获取该设备的软件版本

String softwareVersion=tm.getDeviceSoftwareVersion()

//获取语音信箱号码
String voiceMailNumber=tm.getVoiceMailNumber();

获取手机类型CDMA/ GSM/无

int phoneType=tm.getPhoneType();

switch (phoneType) 
{
    case (TelephonyManager.PHONE_TYPE_CDMA):
               // your code
                   break;
    case (TelephonyManager.PHONE_TYPE_GSM) 
               // your code                 
                   break;
    case (TelephonyManager.PHONE_TYPE_NONE):
               // your code              
                    break;
 }

判断手机是否在漫游,如果漫游返回true

boolean isRoaming=tm.isNetworkRoaming();
if(isRoaming)
      phoneDetails+="\nIs In Roaming : "+"YES";
else
     phoneDetails+="\nIs In Roaming : "+"NO";

获取SIM卡的状态

int SIMState=tm.getSimState();
switch(SIMState)
{
    case TelephonyManager.SIM_STATE_ABSENT :
        // your code
        break;
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED :
        // your code
        break;
    case TelephonyManager.SIM_STATE_PIN_REQUIRED :
        // your code
        break;
    case TelephonyManager.SIM_STATE_PUK_REQUIRED :
        // your code
        break;
    case TelephonyManager.SIM_STATE_READY :
        // your code
        break;
    case TelephonyManager.SIM_STATE_UNKNOWN :
        // your code
        break;

}

获取网络信息

// Get connected network country ISO code
String networkCountry = telephonyManager.getNetworkCountryIso();

// Get the connected network operator ID (MCC + MNC)
String networkOperatorId = telephonyManager.getNetworkOperator();

// Get the connected network operator name
String networkName = telephonyManager.getNetworkOperatorName();

// Get the type of network you are connected with 
int networkType = telephonyManager.getNetworkType();
switch (networkType) {
case (TelephonyManager.NETWORK_TYPE_1xRTT) :"  Your Code ":
break;
case (TelephonyManager.NETWORK_TYPE_CDMA) :"  Your Code ":
break;
case (TelephonyManager.NETWORK_TYPE_EDGE) : "  Your Code ":
break;
case (TelephonyManager.NETWORK_TYPE_EVDO_0) :"  Your Code ":
break;

获取SIM卡的信息

int simState = telephonyManager.getSimState();
switch (simState) 
{
   case (TelephonyManager.SIM_STATE_ABSENT): break;
   case (TelephonyManager.SIM_STATE_NETWORK_LOCKED): break;
   case (TelephonyManager.SIM_STATE_PIN_REQUIRED): break;
   case (TelephonyManager.SIM_STATE_PUK_REQUIRED): break;
   case (TelephonyManager.SIM_STATE_UNKNOWN): break;
   case (TelephonyManager.SIM_STATE_READY): 
    {
        // Get the SIM country ISO code
        String simCountry = telephonyManager.getSimCountryIso();
        // Get the operator code of the active SIM (MCC + MNC)
        String simOperatorCode = telephonyManager.getSimOperator();
        // Get the name of the SIM operator
        String simOperatorName = telephonyManager.getSimOperatorName();
        // -- Requires READ_PHONE_STATE uses-permission --
        // Get the SIM’s serial number
        String simSerial = telephonyManager.getSimSerialNumber();
  }
}

翻译文章:Using Telephony Manager In Android with Example

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值