Code example for TelephonyManager

Methods: getCellLocation, getNetworkOperator, getNetworkType

2
	} 
 
	private CdmaCellLocation location = null;
    public String GetApnPosition() {
 
				int type = tm.getNetworkType();
				//���й��ƶ���2G��EGDE����ͨ��2GΪGPRS�����ŵ�2GΪCDMA�����ŵ�3GΪEVDO  
				//String OperatorName = tm.getNetworkOperatorName();  
				Location loc = null;
				ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>();
				//�й����Ϊ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();
					int cellIDs = location.getBaseStationId();
					int networkID = location.getNetworkId();
					StringBuilder nsb = new StringBuilder();
					nsb.append(location.getSystemId());
                    CellIDInfo info = new CellIDInfo();
                    info.cellId = cellIDs;
                    info.locationAreaCode = networkID; //ok
                    info.mobileNetworkCode = nsb.toString();
                    info.mobileCountryCode = tm.getNetworkOperator().substring(0, 3);
                    info.radioType = "cdma";
                    CellID.add(info);
				} 
				//�ƶ�2G�� + CMCC + 2  
				//type = NETWORK_TYPE_EDGE 
				else if(type == TelephonyManager.NETWORK_TYPE_EDGE)
				{ 
					GsmCellLocation location = (GsmCellLocation)tm.getCellLocation();  
					int cellIDs = location.getCid();  
					int lac = location.getLac(); 
					CellIDInfo info = new CellIDInfo();
                    info.cellId = cellIDs;
                    info.locationAreaCode = lac;
                    info.mobileNetworkCode = tm.getNetworkOperator().substring(3, 5);   
                    info.mobileCountryCode = tm.getNetworkOperator().substring(0, 3);
                    info.radioType = "gsm";
                    CellID.add(info);
				} 
				//��ͨ��2G������� China Unicom   1 NETWORK_TYPE_GPRS 
				else if(type == TelephonyManager.NETWORK_TYPE_GPRS)
				{ 
					GsmCellLocation location = (GsmCellLocation)tm.getCellLocation();  
					int cellIDs = location.getCid();  
					int lac = location.getLac(); 
					CellIDInfo info = new CellIDInfo();
                    info.cellId = cellIDs;
                    info.locationAreaCode = lac;