---
title: "Android 获取基站信息"
author: "luckliu521"
date: "2013-10-18T10:39:35Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2013-10-18T10:39:35Z"
id: 1960281
url: "https://pay.iteye.com/blog/1960281"
---

Android 基站分CdmaCellLocation和GsmCellLocation，要根据不同的SIM卡转成不同的对象
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
   int type = tm.getNetworkType();//获取网络类型
//在中国，移动的2G是EGDE，联通的2G为GPRS，电信的2G为CDMA，电信的3G为EVDO
Location loc = null;
ArrayList CellID = new ArrayList();
//中国电信为CTC
//NETWORK_TYPE_EVDO_A是中国电信3G的getNetworkType
//NETWORK_TYPE_CDMA电信2G是CDMA
if (type == TelephonyManager.NETWORK_TYPE_EVDO_A || type == TelephonyManager.NETWORK_TYPE_CDMA || type ==TelephonyManager.NETWORK_TYPE_1xRTT)
{
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
throw new Exception("errr");
String operator = tm.getNetworkOperator();
 int cellIDs = location.getBaseStationId();
  	int networkID = location.getNetworkId();
  	StringBuilder sb = new StringBuilder();
 sb.append(location.getSystemId());
int mnc = Integer.parseInt(nsb.toString());
int mcc = Integer.parseInt(operator.substring(0,3));
 
 
}
//移动2G卡 + CMCC + 2
//type = NETWORK_TYPE_EDGE
//联通的2G经过测试 China Unicom 1 NETWORK_TYPE_GPRS
else if(type == TelephonyManager.NETWORK_TYPE_EDGE || type == TelephonyManager.NETWORK_TYPE_GPRS)
{
GsmCellLocation location = (GsmCellLocation)tm.getCellLocation();
location = (CdmaCellLocation) tm.getCellLocation();
if(location == null)
throw new Exception("errr");
String operator = tm.getNetworkOperator();
int mcc = Integer.parseInt(operator.substring(0,3));
int mnc = Integer.parseInt(operator.substring(3));
int cid = location.getCid();
int lac = location.getLac();
}