Android 用代码获取基站号(cell)和小区号(lac)

Android 用代码获取基站号(cell)和小区号(lac)

用手机定位的时候需要的参数,不多说了,直接上代码:

联通移动获取方式:

TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cel = tel.getCellLocation(); 
int nPhoneType = tel.getPhoneType();
//移动联通 GsmCellLocation
if (nPhoneType == 2 && cel instanceof GsmCellLocation) {
	GsmCellLocation gsmCellLocation = (GsmCellLocation) cel;
	int nGSMCID = gsmCellLocation.getCid();
	if (nGSMCID > 0) {
		if (nGSMCID != 65535) {
			this.cell = nGSMCID;
			this.lac = gsmCellLocation.getLac();
		}
	}
}

电信获取方式:


TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
CellLocation cel = tel.getCellLocation(); 
int nPhoneType = tel.getPhoneType();
//电信   CdmaCellLocation
if (nPhoneType == 2 && cel instanceof CdmaCellLocation) {
	Log.e("电信", "-----------------》电信");
	CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cel;
	sid=cdmaCellLocation.getSystemId();
	nid=cdmaCellLocation.getNetworkId();
	bid=cdmaCellLocation.getBaseStationId();
}
		


你可能感兴趣的:(Android)