Code example for TelephonyManager

Methods: getCellLocationgetPhoneType

0
	 
	public static CellLogEntry getCurrentCell(Context ctx)  
	{ 
		CellLogEntry cell = null;
		final TelephonyManager telephony = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
		if ((telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
			|| (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA))
		{ 
		    final CellLocation location = telephony.getCellLocation();
		    if (location != null)
		    { 
		    	if (location instanceof GsmCellLocation)
		    	{ 
		    		GsmCellLocation gsmLoc = (GsmCellLocation) location;
			        Log.i(TAG, "Detected cell LAC: " + gsmLoc.getLac() + " CID: " + gsmLoc.getCid());
			        cell = new CellLogEntry(gsmLoc.getCid(), gsmLoc.getLac());
		    	} 
		    	else if (location instanceof CdmaCellLocation)
		    	{ 
		    		CdmaCellLocation cdmaLoc = (CdmaCellLocation) location;
			        Log.i(TAG, "Detected cell NID: " + cdmaLoc.getNetworkId() + " BID: " + cdmaLoc.getBaseStationId());
			        cell = new CellLogEntry(cdmaLoc.getBaseStationId(), cdmaLoc.getNetworkId());
		    	} 
		    } 
	    	else 
	    	{ 
		        Log.i(TAG, "Unknown phone type " + telephony.getPhoneType());
	    	} 
		} 
		 
		return cell;
	} 
Connect your IDE to all the code out there  Get Codota for Java