安卓中的GSM网络信息

5

有人知道如何在安卓中获取GSM信息吗?例如BCCH(广播控制频道)和BCIS(基站识别码)。我已经获得了LAC(位置区域码)和CID(小区标识符)。我知道这是一个底层的信息,但是否有人知道如何获取这些信息?我在研究方面遇到了困难,对移动网络也不了解。请帮忙,谢谢 :)

3个回答

4

这里是一个函数,它可以给你完整的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
请查看此帖子 https://groups.google.com/forum/#!topic/android-platform/tVyNMnXtcEI - khurram
你和Anchit有相同的答案。:( 是否无法真正获取网络的低级信息? - GummyBear0014
两个SIM卡怎么样? - Bugs Happen
有没有获取BTS ID的任何方法? - Flash Thunder

2
请访问此处。它解释了没有可用的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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接