在andorid上面要獲取手機網絡信息通常要調用TelephonyManagerl類來獲取相關信息。java
MCC,Mobile Country Code,移動國家代碼(中國的爲460);android
MNC,Mobile Network Code,移動網絡號碼(中國移動爲0,中國聯通爲1,中國電信爲2); api
LAC,Location Area Code,位置區域碼;網絡
CID,Cell Identity,基站編號;app
BSSS,Base station signal strength,基站信號強度。ide
eNB E-UTRAN Node B 爲LTE系統中E-UTRAN的組成部分ui
計算eNB的方式是 ci = eNB*256+cidthis
首先要設置一些權限來獲取spa
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
獲取TelephonyManagerl.net
telephonymanager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
先獲取小區信息
getNeighboringCellInfo ()已經被谷歌棄用
This method was deprecated in API level 23.
Use (@link getAllCellInfo} which returns a superset of the information from NeighboringCellInfo.
StringBuilder str = new StringBuilder(); //獲取小區信息 List<CellInfo> cellInfoList = telephonymanager.getAllCellInfo(); str.append("小區信息:"+"\n"); int index = 0; for (CellInfo cellInfo : cellInfoList) { //獲取全部Lte網絡信息 if (cellInfo instanceof CellInfoLte) { str.append("["+index+"]==CellInfoLte"+"\n"); if(cellInfo.isRegistered()){ str.append("isRegistered=YES"+"\n"); } str.append("TimeStamp:"+cellInfo.getTimeStamp()+"\n"); str.append(((CellInfoLte)cellInfo).getCellIdentity().toString()+"\n"); str.append(((CellInfoLte)cellInfo).getCellSignalStrength().toString()+"\n"); } //獲取全部的cdma網絡信息 if(cellInfo instanceof CellInfoCdma){ str.append("["+index+"]==CellInfoCdma"+"\n"); if(cellInfo.isRegistered()){ str.append("isRegistered=YES"+"\n"); } str.append("TimeStamp:"+cellInfo.getTimeStamp()+"\n"); str.append(((CellInfoCdma)cellInfo).getCellIdentity().toString()+"\n"); str.append(((CellInfoCdma)cellInfo).getCellSignalStrength().toString()+"\n"); } //獲取全部的Gsm網絡 if(cellInfo instanceof CellInfoGsm){ str.append("["+index+"]==CellInfoGsm"+"\n"); if(cellInfo.isRegistered()){ str.append("isRegistered=YES"+"\n"); } str.append("TimeStamp:"+cellInfo.getTimeStamp()+"\n"); str.append(((CellInfoGsm)cellInfo).getCellIdentity().toString()+"\n"); str.append(((CellInfoGsm)cellInfo).getCellSignalStrength().toString()+"\n"); } //獲取全部的Wcdma網絡 if(cellInfo instanceof CellInfoWcdma){ str.append("["+index+"]==CellInfoWcdma"+"\n"); if(cellInfo.isRegistered()){ str.append("isRegistered=YES"+"\n"); } str.append("TimeStamp:"+cellInfo.getTimeStamp()+"\n"); str.append(((CellInfoWcdma)cellInfo).getCellIdentity().toString()+"\n"); str.append(((CellInfoWcdma)cellInfo).getCellSignalStrength().toString()+"\n"); } index++; }
獲取手機的位置
CellLocation location = telephonymanager.getCellLocation(); if (location != null && location instanceof GsmCellLocation) { GsmCellLocation l1 = (GsmCellLocation) location; str.append("使用網絡:" + "Gsm" + "\n"); str.append("cid"+l1.getCid()+ "\n"); str.append("lac"+l1.getLac()+ "\n"); str.append("Psc"+l1.getPsc()+ "\n"); } else if(location != null && location instanceof CdmaCellLocation){ CdmaCellLocation l2 = (CdmaCellLocation) location; str.append(l2.toString() + "\n"); }
而後能夠將數據顯示出來
小區信息:
[0]==CellInfoLte
isRegistered=YES
TimeStamp:332243302229569
CellIdentityLte:{ mMcc=460 mMnc=1 mCi=135153925 mPci=442 mTac=22789}
CellSignalStrengthLte: ss=23 rsrp=-94 rsrq=-4 rssnr=2147483647 cqi=2147483647 ta=2147483647
[1]==CellInfoLte
TimeStamp:332243302229569
CellIdentityLte:{ mMcc=2147483647 mMnc=2147483647 mCi=2147483647 mPci=456 mTac=2147483647}
CellSignalStrengthLte: ss=14 rsrp=-99 rsrq=-4 rssnr=2147483647 cqi=2147483647 ta=2147483647
[2]==CellInfoLte
TimeStamp:332243302229569
CellIdentityLte:{ mMcc=2147483647 mMnc=2147483647 mCi=2147483647 mPci=144 mTac=2147483647}
CellSignalStrengthLte: ss=17 rsrp=-110 rsrq=-20 rssnr=2147483647 cqi=2147483647 ta=2147483647
[3]==CellInfoLte
TimeStamp:332243302229569
CellIdentityLte:{ mMcc=2147483647 mMnc=2147483647 mCi=2147483647 mPci=162 mTac=2147483647}
CellSignalStrengthLte: ss=17 rsrp=-110 rsrq=-14 rssnr=2147483647 cqi=2147483647 ta=2147483647
[4]==CellInfoLte
TimeStamp:332243302229569
CellIdentityLte:{ mMcc=2147483647 mMnc=2147483647 mCi=2147483647 mPci=303 mTac=2147483647}
CellSignalStrengthLte: ss=14 rsrp=-110 rsrq=-14 rssnr=2147483647 cqi=2147483647 ta=2147483647
[5]==CellInfoLte
TimeStamp:332243302229569
CellIdentityLte:{ mMcc=2147483647 mMnc=2147483647 mCi=2147483647 mPci=2 mTac=2147483647}
CellSignalStrengthLte: ss=16 rsrp=-113 rsrq=-20 rssnr=2147483647 cqi=2147483647 ta=2147483647
這是我用本身的聯通4g的手機獲取到的數據信息,可是我獲取到的cid和在小區信息中的CellInfoLte的ci是同一個值,緣由我不是很清楚。
Google api中對telephonymanager.getCellLocation()的解釋是
Returns the current location of the device.
If there is only one radio in the device and that radio has an LTE connection, this method will return null. The implementation must not to try add LTE identifiers into the existing cdma/gsm classes.
In the future this call will be deprecated.
其餘的東西在等等完善