简单记录,获取基站信息

好早之前参考他人文章写得。记录在此。

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


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值