我在CDMA连接时如何获得网络小区ID?

时间:2013-02-19 11:51:20

标签: android

我可以使用GsmCellLocation对象获取我的网络单元ID。但是当我使用CDMA,3G,HSDPA或UMTS时.....我无法获得Cell ID。使用带有3G连接的GsmCellLocation.getCid()检索一个叫做LCID(逻辑信道ID)的东西,它不是Cid。我用来获取Gsm Cell ID的代码如下所示:

private PhoneStateListener mPhoneLocationListener = new PhoneStateListener() {
    public void onCellLocationChanged(CellLocation location) {
                    TelephonyManager tm  = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);                      
           GsmCellLocation location2 = (GsmCellLocation) tm.getCellLocation();
           cellId = location2.getCid();
    }
}

但是当我换行时:

GsmCellLocation location2 = (GsmCellLocation) tm.getCellLocation();

到:

CdmaCellLocation location2 = (CdmaCellLocation) tm.getCellLocation();

即使我强迫我的设备仅连接到CDMA,也会引发异常,CastException表示无法将GsmCellLocation强制转换为CdmaCellLocation

那么如何才能获得3g的手机信息?

2 个答案:

答案 0 :(得分:0)

尝试这样的事情

CellLocation cl = tm.getCellLocation();
        GsmCellLocation gsmLoc;
        CdmaCellLocation cdmaLoc;
        try {
            gsmLoc = (GsmCellLocation) cl;
            System.out.println(gsmLoc.getCid());
        } catch (ClassCastException e) {
            cdmaLoc = (CdmaCellLocation) cl;
            System.out.println("Base station ID - "+ cdmaLoc.getBaseStationId());
        }

答案 1 :(得分:0)

CDMA没有Cell ID。相反,它有3个标识符:

  1. SID - 系统ID
  2. NID - 网络ID
  3. BID - 基站ID
  4. 有关更多信息,请参阅OpenCellID wiki的此页面: http://wiki.opencellid.org/wiki/Public:CDMA