我可以使用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的手机信息?
答案 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)
有关更多信息,请参阅OpenCellID wiki的此页面: http://wiki.opencellid.org/wiki/Public:CDMA