Code example for TelephonyManager

Methods: getCallState, getCellLocation, getDeviceId, getDeviceSoftwareVersion, getNetworkOperator, getNetworkOperatorName, getSimSerialNumber, getSubscriberId

0
		TelephonyManager telephonyManager =
		(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		 
		 
		/** Network Information **/ 
		String nomOperateurReseau = telephonyManager.getNetworkOperatorName();
		if (nomOperateurReseau != null)
		{ 
			Log.v("Network Operator Name", nomOperateurReseau);
		} 
		 
		/** CellID Lookup **/	 
		GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();
		try { 
		int cid = location.getCid();
		int lac = location.getLac();
		if (Integer.toString(cid) != null && Integer.toString(lac) != null) {
			Log.v("CellID Information", Integer.toString(cid));
			Log.v("Location Area Code Information", Integer.toString(lac));
		} 
		} 
		catch (NullPointerException e) {
			String err = (e.getMessage()==null)?"CellID Information OR Location Area Code Information":e.getMessage();
			Log.e("GSMCellLocation Exception", err);
		} 
 
 
		 
		String networkOperator = telephonyManager.getNetworkOperator();
		 
		if ((networkOperator != null) && (networkOperator.length() > 0)) {
			try { 
				int mcc = Integer.parseInt(networkOperator.substring(0, 3));
				int mnc = Integer.parseInt(networkOperator.substring(3));
				Log.v("MCC Information", Integer.toString(mcc));
				Log.v("MNC Information", Integer.toString(mnc));
				 
			}  
			catch (NumberFormatException e) {
				Log.e("NumberFormatException", e.getMessage());
 
			} 
		} 
		 
		/** Phone state **/ 
		int etat = telephonyManager.getCallState();
		switch(etat) {
		 
			/** IDLE **/ 
			case TelephonyManager.CALL_STATE_IDLE:
				Log.v("Phone State", "Idle");
				break; 
			 
			/** Call Incoming **/ 
			case TelephonyManager.CALL_STATE_RINGING:
				Log.v("Phone State", "Ringing");
				break; 
			 
			/** Call dialing, active or paused **/ 
			case TelephonyManager.CALL_STATE_OFFHOOK:
				Log.v("Phone State", "Active");
				break; 
			 
			default: 
				Log.v("Phone State", "Other " + etat);
				break; 
		} 
		 
		/** Device Information **/ 
		String idAppareil = telephonyManager.getDeviceId();
		if (idAppareil != null)
		{ 
			Log.v("Device ID", idAppareil);
		} 
		 
		/** IMSI **/ 
		String IMSI = telephonyManager.getSubscriberId();
		if (IMSI != null)
		{ 
			Log.v("IMSI", IMSI);
		} 
		 
		/** Software Version **/ 
		String versionSoftwareAppareil =
		telephonyManager.getDeviceSoftwareVersion();
		if (versionSoftwareAppareil != null)
		{ 
			Log.v("Software Version", versionSoftwareAppareil);
		} 
		 
		/** SIM Information **/ 
		String numeroSerieSIM = telephonyManager.getSimSerialNumber();
		if (numeroSerieSIM != null)
		{ 
			Log.v("SIM", numeroSerieSIM);
		}