2013-11-28 40 views
4

有人知道如何在android中獲取GSM信息嗎?諸如BCCH(廣播控制信道)和BCIS(基站標識碼)之類的信息。我已經獲得了LAC(位置區號)和CID(小區ID)。我知道這是一個低級別的信息,但有人知道獲得這些信息?我很難研究,我對蜂窩網絡一無所知。請幫助謝謝:)Android中的GSM網絡信息

回答

3

這裏是功能,它給你的GSM網絡的完整信息。 只是情境呼叫從活動

private void getNWInfo(Context context) { 
      /** 
      * <uses-permission android:name="android.permission.READ_PHONE_STATE" 
      * /> <uses-permission 
      * android:name="android.permission.ACCESS_NETWORK_STATE"/> 
      */ 

      TelephonyManager telephonyManager = (TelephonyManager) context 
         .getSystemService(Context.TELEPHONY_SERVICE); 
      String networkOperator = telephonyManager.getNetworkOperator(); 
      int mcc = 0, mnc = 0; 
      if (networkOperator != null) { 
       mcc = Integer.parseInt(networkOperator.substring(0, 3)); 
       mnc = Integer.parseInt(networkOperator.substring(3)); 
      } 

      String SimNumber = telephonyManager.getLine1Number(); 

      String SimSerialNumber = telephonyManager.getSimSerialNumber(); 
      String countryISO = telephonyManager.getSimCountryIso(); 
      String operatorName = telephonyManager.getSimOperatorName(); 
      String operator = telephonyManager.getSimOperator(); 
      int simState = telephonyManager.getSimState(); 

      String voicemailNumer = telephonyManager.getVoiceMailNumber(); 
      String voicemailAlphaTag = telephonyManager.getVoiceMailAlphaTag(); 

      // Getting connected network iso country code 
      String networkCountry = telephonyManager.getNetworkCountryIso(); 
      // Getting the connected network operator ID 
      String networkOperatorId = telephonyManager.getNetworkOperator(); 
      // Getting the connected network operator name 
      String networkName = telephonyManager.getNetworkOperatorName(); 

      int networkType = telephonyManager.getNetworkType(); 

      String network = ""; 
      ConnectivityManager cm = (ConnectivityManager) context 
         .getSystemService(Context.CONNECTIVITY_SERVICE); 
      try { 
       if (cm.getActiveNetworkInfo().getTypeName().equals("MOBILE")) 
         network = "Cell Network/3G"; 
       else if (cm.getActiveNetworkInfo().getTypeName().equals("WIFI")) 
         network = "WiFi"; 
       else 
         network = "N/A"; 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      TextView textView = (TextView) findViewById(R.id.textView); 
      textView.setText("network :" + network + 

      "\n" + "countryISO : " + countryISO + "\n" + "operatorName : " 
         + operatorName + "\n" + "operator :  " + operator + "\n" 
         + "simState :" + simState + "\n" + "Sim Serial Number : " 
         + SimSerialNumber + "\n" + "Sim Number : " + SimNumber + "\n" 
         + "Voice Mail Numer" + voicemailNumer + "\n" 
         + "Voice Mail Alpha Tag" + voicemailAlphaTag + "\n" 
         + "Sim State" + simState + "\n" + "Mobile Country Code MCC : " 
         + mcc + "\n" + "Mobile Network Code MNC : " + mnc + "\n" 
         + "Network Country : " + networkCountry + "\n" 
         + "Network OperatorId : " + networkOperatorId + "\n" 
         + "Network Name : " + networkName + "\n" + "Network Type : " 
         + networkType); 


    } 

你可以找到這個博客

http://khurramitdeveloper.blogspot.in/search?updated-max=2013-11-07T03:23:00-08:00&max-results=7

希望它會幫助你:)

+1

怎麼樣BCCH和BSIC?你有想法來檢索這些信息嗎? – GummyBear0014

+0

請通過這個線程https://groups.google.com/forum/#!topic/android-platform/tVyNMnXtcEI – khurram

+0

你和anchit有相同的答案。 :(請問網絡的低級別信息是不是真的可能檢索到? – GummyBear0014

2

請訪問here更多細節。它解釋說沒有API可用於獲取無線電信息。

0

你可以試試這個:

public static JSONArray getCellInfo(Context ctx){ 
    TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); 

    JSONArray cellList = new JSONArray(); 

    int phoneTypeInt = tel.getPhoneType(); 
    String phoneType = "unknown"; 
    if (phoneTypeInt == TelephonyManager.PHONE_TYPE_GSM) 
     phoneType = "gsm"; 
    else if (phoneTypeInt == TelephonyManager.PHONE_TYPE_CDMA) 
     phoneType = "cdma"; 

    //from Android M up must use getAllCellInfo 
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { 

     List<NeighboringCellInfo> neighCells = tel.getNeighboringCellInfo(); 
     for (int i = 0; i < neighCells.size(); i++) { 
      try { 
       JSONObject cellObj = new JSONObject(); 
       NeighboringCellInfo thisCell = neighCells.get(i); 
       cellObj.put("cellId", thisCell.getCid()); 
       cellObj.put("lac", thisCell.getLac()); 
       cellObj.put("rssi", thisCell.getRssi()); 
       cellList.put(cellObj); 
      } catch (Exception e) { 
      } 
     } 

    } else { 
     List<CellInfo> infos = tel.getAllCellInfo(); 
     for (int i = 0; i < infos.size(); ++i) { 
      try { 
       JSONObject cellObj = new JSONObject(); 
       CellInfo info = infos.get(i); 
       if (info instanceof CellInfoGsm) { 
        CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength(); 
        CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity(); 
        cellObj.put("cellId", identityGsm.getCid()); 
        cellObj.put("lac", identityGsm.getLac()); 
        cellObj.put("dbm", gsm.getDbm()); 
        cellList.put(cellObj); 
       } else if (info instanceof CellInfoLte) { 
        CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength(); 
        CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity(); 
        cellObj.put("cellId", identityLte.getCi()); 
        cellObj.put("tac", identityLte.getTac()); 
        cellObj.put("dbm", lte.getDbm()); 
        cellList.put(cellObj); 
       } 

      } catch (Exception ex) { 

      } 
     } 
    } 

    return cellList; 
}