Code example for TelephonyManager

Methods: getCellLocation, getNetworkOperator, getNetworkType

0
	 * fetch the current cell info from the phone. 
	 */ 
	public void updateCell() { 
 
		try { 
			location = (GsmCellLocation) tm.getCellLocation();
			cid = location.getCid();
			lac = location.getLac();
		} catch (Exception e) {
			// TODO: handle exception 
		} 
 
		/* 
		 * Mcc and mnc is concatenated in the networkOperatorString. The first 3 
		 * chars is the mcc and the last 2 is the mnc. 
		 */ 
		String networkOperator = tm.getNetworkOperator();
		if (networkOperator != null && networkOperator.length() > 0) {
			try { 
				mcc = Integer.parseInt(networkOperator.substring(0, 3));
				mnc = Integer.parseInt(networkOperator.substring(3));
			} catch (Exception e) {
			} 
		} 
 
		/* 
		 * Check if the current cell is a UMTS (3G) cell. If a 3G cell the cell 
		 * id padding will be 8 numbers, if not 4 numbers. 
		 */ 
		if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) {
			cellPadding = 8;
		} else { 
			cellPadding = 4;
		}