Android擷取手機號碼及電訊廠商

來源:互聯網
上載者:User

標籤: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();

Android擷取手機號碼及電訊廠商

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.