好早之前参考他人文章写得。记录在此。
public int cellId;// 基站编号
public String mobileCountryCode;// 移动国家代码 中国为460
public String mobileNetworkCode;// 移动网络号码 移动0,联通1,电信2
public int locationAreaCode;// 位置区域码
public String radioType;// 网络制式
public int RSSI;// 基站信号强度
static NetworkInfo smNetWorkInfo = null;
public static NetworkInfo getNetWorkInfo() {
if (smNetWorkInfo == null) {
smNetWorkInfo = new NetworkInfo();
}
return smNetWorkInfo;
}
public void cancel() {
if (smNetWorkInfo != null) {
smNetWorkInfo = null;
}
}
public void upLoad() {
Log.d("network info ", cellId + "--" + mobileCountryCode + "--"
+ mobileNetworkCode + "--" + locationAreaCode + "--"
+ radioType + "--" + RSSI);
}
public void GetNetworkInfo() {
// TODO Auto-generated method stub
ArrayList<NetworkInfo> infos = new ArrayList<NetworkInfo>();
TelephonyManager mTelephonyManager = (TelephonyManager) GPSApplication
.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
NetworkInfo currentinfo = new NetworkInfo();
int type = mTelephonyManager.getNetworkType();
// GSM
if (type == TelephonyManager.NETWORK_TYPE_GPRS
|| type == TelephonyManager.NETWORK_TYPE_EDGE
|| type == TelephonyManager.NETWORK_TYPE_HSDPA) {
Log.d("NetworkInfo", "gsm location");
GsmCellLocation gsmCellLocation = (GsmCellLocation) mTelephonyManager
.getCellLocation();
if (gsmCellLocation == null) {
return;
}
int lac = gsmCellLocation.getLac();
String mcc = mTelephonyManager.getNetworkOperator().substring(0, 3);
String mnc = mTelephonyManager.getNetworkOperator().substring(3, 5);
currentinfo.cellId = gsmCellLocation.getCid();
currentinfo.mobileCountryCode = mcc;
currentinfo.mobileNetworkCode = mnc;
currentinfo.locationAreaCode = lac;
currentinfo.radioType = "gsm";
infos.add(currentinfo);
// 获取基站信息
List<NeighboringCellInfo> list = mTelephonyManager
.getNeighboringCellInfo();
for (int i = 0; i < list.size(); i++) {
NetworkInfo info = new NetworkInfo();
info.cellId = list.get(i).getCid();
info.mobileCountryCode = mcc;
info.mobileNetworkCode = mnc;
info.locationAreaCode = lac;
info.radioType = "gsm";
info.RSSI = list.get(i).getRssi();
infos.add(info);
}
}
// 电信cdma网
else if (type == TelephonyManager.NETWORK_TYPE_CDMA
|| type == TelephonyManager.NETWORK_TYPE_1xRTT
|| type == TelephonyManager.NETWORK_TYPE_EVDO_0
|| type == TelephonyManager.NETWORK_TYPE_EVDO_A) {
CdmaCellLocation cdma = (CdmaCellLocation) mTelephonyManager
.getCellLocation();
int lac = cdma.getNetworkId();
String mcc = mTelephonyManager.getNetworkOperator().substring(0, 3);
String mnc = String.valueOf(cdma.getSystemId());
int cid = cdma.getBaseStationId();
currentinfo.cellId = cid;
currentinfo.mobileCountryCode = mcc;
currentinfo.mobileNetworkCode = mnc;
currentinfo.locationAreaCode = lac;
currentinfo.radioType = "cdma";
infos.add(currentinfo);
// 获得邻近基站信息
List<NeighboringCellInfo> list = mTelephonyManager
.getNeighboringCellInfo();
int size = list.size();
for (int i = 0; i < size; i++) {
NetworkInfo info = new NetworkInfo();
info.cellId = list.get(i).getCid();
info.mobileCountryCode = mcc;
info.mobileNetworkCode = mnc;
info.locationAreaCode = lac;
info.RSSI = list.get(i).getRssi();
infos.add(info);
}
}
for (int i = 0; i < infos.size(); i++) {
infos.get(i).upLoad();
}
}