欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中TelephonyManager用法實(shí)例

 更新時(shí)間:2016年03月10日 10:55:56   作者:yhm2046  
這篇文章主要介紹了Android中TelephonyManager用法,結(jié)合實(shí)例形式分析了TelephonyManager類(lèi)的功能,使用技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Android中TelephonyManager用法。分享給大家供大家參考,具體如下:

一、概述:

TelephonyManager類(lèi)主要提供了一系列用于訪問(wèn)與手機(jī)通訊相關(guān)的狀態(tài)和信息的get方法。其中包括手機(jī)SIM的狀態(tài)和信息、電信網(wǎng)絡(luò)的狀態(tài)及手機(jī)用戶(hù)的信息。在應(yīng)用程序中可以使用這些get方法獲取相關(guān)數(shù)據(jù)。

TelephonyManager類(lèi)的對(duì)象可以通過(guò)Context.getSystemService(Context.TELEPHONY_SERVICE)方法來(lái)獲得,需要注意的是有些通訊信息的獲取對(duì)應(yīng)用程序的權(quán)限有一定的限制,在開(kāi)發(fā)的時(shí)候需要為其添加相應(yīng)的權(quán)限。

二、示例:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // 讀取sim卡
    TelephonyManager tm = (TelephonyManager) this
        .getSystemService(Context.TELEPHONY_SERVICE);
    //
    // String tel = tm.getLine1Number(); // 取出MSISDN,很可能為空
    // String iccid = tm.getSimSerialNumber(); // 取出ICCID
    // String imsi = tm.getSubscriberId(); // 取出IMSI
    System.out.println(tm.getCallState());
    System.out.println(tm.getDataActivity());
    System.out.println(tm.getDataState());
    System.out.println("得到設(shè)備的ID,IMEI或者M(jìn)EID:" + tm.getDeviceId());
    System.out.println("軟件版本:"+tm.getDeviceSoftwareVersion());
    if (tm.getLine1Number()!=null) {
      System.out.println("電話(huà)號(hào)碼:"+tm.getLine1Number());
    } else {
      System.out.println("電話(huà)號(hào)碼為空");
    }
    System.out.println("電信網(wǎng)路國(guó)別:" + tm.getNetworkCountryIso()); // 電信網(wǎng)路國(guó)別
    System.out.println("電信公司代號(hào):" + tm.getNetworkOperator());
    System.out.println("電信公司名稱(chēng):" + tm.getNetworkOperatorName());
    // System.out.println(tm.getNetworkType());
    // 行動(dòng)網(wǎng)路類(lèi)型
    String[] networkTypeArray = { "UNKNOWN", "GPRS", "EDGE", "UMTS",
        "CDMA", "EVDO 0", "EVDO A", "1xRTT", "HSDPA", "HSUPA", "HSPA" };
    String networkType = networkTypeArray[tm.getNetworkType()];
    System.out.println("行動(dòng)網(wǎng)路類(lèi)型:"+networkType);
//   System.out.println(tm.getPhoneType());
    // 行動(dòng)通訊類(lèi)型
    String[] phoneTypeArray = {"NONE", "GSM", "CDMA"};
    String phoneType = phoneTypeArray[tm.getPhoneType()];
    System.out.println("行動(dòng)通訊類(lèi)型:"+phoneType);
    System.out.println("sim國(guó)家代碼:"+tm.getSimCountryIso());
    System.out.println(tm.getSimOperator());
    System.out.println(tm.getSimOperatorName());
    // System.out.println(tm.getSimSerialNumber());
    System.out.println(tm.getSimState());
    // System.out.println(tm.getSubscriberId()); // 手機(jī) IMSI
    System.out.println(tm.getVoiceMailAlphaTag());
//    System.out.println("得到位置信息,主要是當(dāng)前注冊(cè)小區(qū)的位置碼:"+tm.getCellLocation());
    // System.out.println(tm.getNeighboringCellInfo());
    // 手機(jī)漫游狀態(tài)
    String roamingStatus = tm.isNetworkRoaming() ? "漫游中" : "非漫游";
    System.out.println(roamingStatus);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論