Code example for TelephonyManager

Methods: getCellLocation, getDeviceId, getPhoneType, getSubscriberId

0
	} 
	 
	public static String getCellId() {	
		String out = "";
		try { 
			if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
				final GsmCellLocation gLoc = (GsmCellLocation) tm.getCellLocation();
				if(gLoc != null)
					out = Integer.toString(gLoc.getCid());
			} 
			return out;
		} catch(NullPointerException e) {
			return ""; 
		} 
	} 
	 
	public static String getLAC() {
		String out = "";
		try { 
			if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM){
				final GsmCellLocation gLoc = (GsmCellLocation) tm.getCellLocation();
				if(gLoc != null)
					out = Integer.toString(gLoc.getLac());
			} 
			return out;		
		} catch(NullPointerException e) {
			return ""; 
		} 
		 
	} 
	 
	public static String getIMSI() {
		String out = "";
		try { 
			out = tm.getSubscriberId();
			return out;
		} catch(NullPointerException e) {
			return ""; 
		} 
	} 
	 
	public static String getMCC() {
		String out = "";
		try { 
			out = tm.getNetworkOperator().substring(0,3);
			return out;
		} catch(NullPointerException e) {
			return ""; 
		} 
	} 
	 
	public static String getMNC() {
		String out = "";
		try { 
			out = tm.getNetworkOperator().substring(3);
			return out;
		} catch(NullPointerException e) {
			return ""; 
		} 
	} 
	 
	public static String getIMEI() {
		String out = "";
		try { 
			out = tm.getDeviceId();
			return out;
		} catch(NullPointerException e) {
			return ""; 
		} 
	}