Android獲取手機號碼及運營商
public class PhoneSIMCInfo {
/手機管理工具類*/
private TelephonyManager telephonyManager;
/國際移動用戶識別碼/
private String mImsi;
public PhoneSIMCInfo(Context context) {
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
}
/**獲取手機號: 有些手機號無法獲取,是因為運營商在SIM中沒有寫入手機號/
public String getNativePhoneNumber() {
return telephonyManager.getLine1Number();
}
/獲取手機號碼所屬公司信息*/
public String getProviderCompanyName() {
String mName = null;
/獲取國際移動用戶識別碼(IMSI)*/
mImsi = telephonyManager.getSubscriberId();
try
{
mImsi = telephonyManager.getSubscriberId();
if (mImsi.startsWith("46000")) {
mName = "中國移動";
}else if (mImsi.startsWith("46002")) {
mName = "中國移動";
}else if (mImsi.startsWith("46001")) {
mName = "中國聯通";
}else if (mImsi.startsWith("46003"))
mName = "中國電信";
}
catch (Exception exception)
{
exception.printStackTrace();
}
return mName;
}
}
-----------附帶其它相關信息獲取------------------------------
TelephonyManager telephonyManager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);/手機串號:GSM手機的 IMEI 和 CDMA手機的 MEID.*/
String deviceID =telephonyManager.getDeviceId();
/獲取手機SIM卡的序列號/
String imei =telephonyManager.getSimSerialNumber();
/**電話方位/
CellLocation str =telephonyManager.getCellLocation();
/取得和語音郵件相關的標簽,即為識別符*/
String voiceMail =telephonyManager.getVoiceMailAlphaTag();
/獲取語音郵件號碼/
String voiceMailNumber =telephonyManager.getVoiceMailNumber();
/**獲取ISO國家碼,相當于提供SIM卡的國家碼/
String simCountryIso =telephonyManager.getSimCountryIso();