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();
}
		


發佈了25 篇原創文章 · 獲贊 9 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章