Java Code Examples for android.telephony.CellIdentityGsm#getMcc()

The following examples show how to use android.telephony.CellIdentityGsm#getMcc() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScanService.java    From spidey with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void startScan() {
	
	logMessage("starting tower scan... ");
	Scan scan = new Scan();

	// TODO: Get location from user?
	scan.setLocation(lastScanName);

	// TODO: use actual GPS Coordinates
	scan.setLatitude(lastScanLat);
	scan.setLongitude(lastScanLon);

	long scan_id = db.createScan(scan);

	List<CellInfo> cellInfos = (List<CellInfo>) this.telephonyManager
			.getAllCellInfo();

	// TODO: better error handling of null cellinfos
	if (cellInfos != null) {
		for (CellInfo cellInfo : cellInfos) {

			if (cellInfo instanceof CellInfoGsm) {
				CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;

				CellIdentityGsm cellIdentity = cellInfoGsm
						.getCellIdentity();
				CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm
						.getCellSignalStrength();

				int dbmLevel = cellSignalStrengthGsm.getDbm();
				
				com.spideyapp.sqlite.model.CellInfo cell = new com.spideyapp.sqlite.model.CellInfo(
						cellIdentity.getCid(), cellIdentity.getLac(),
						cellIdentity.getMcc(), cellIdentity.getMnc(),dbmLevel);

				db.createCell(cell, scan_id);

				shareCellInfo (cell);
				
			}
		}
	}

}
 
Example 2
Source File: CellTowerListGsm.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adds or updates a cell tower.
 * <p>
 * If the cell tower is already in the list, its data is updated; if not, a
 * new entry is created.
 * <p>
 * This method will set the cell's identity data, its signal strength and
 * whether it is the currently serving cell. If the API level is 18 or 
 * higher, it will also set the generation.
 * @return The new or updated entry.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public CellTowerGsm update(CellInfoGsm cell) {
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) 
		return null;
	CellIdentityGsm cid = cell.getCellIdentity();
	CellTowerGsm result = null;
	CellTowerGsm cand = this.get(cid.getMcc(), cid.getMnc(), cid.getLac(), cid.getCid());
	if ((cand != null) && CellTower.matches(cid.getPsc(), cand.getPsc()))
		result = cand;
	if (result == null) {
		cand = this.get(cid.getPsc());
		if ((cand != null)
				&& ((cid.getMcc() == Integer.MAX_VALUE) || CellTower.matches(cid.getMcc(), cand.getMcc()))
				&& ((cid.getMnc() == Integer.MAX_VALUE) || CellTower.matches(cid.getMnc(), cand.getMnc()))
				&& ((cid.getLac() == Integer.MAX_VALUE) || CellTower.matches(cid.getLac(), cand.getLac()))
				&& ((cid.getCid() == Integer.MAX_VALUE) ||CellTower.matches(cid.getCid(), cand.getCid())))
			result = cand;
	}
	if (result == null)
		result = new CellTowerGsm(cid.getMcc(), cid.getMnc(), cid.getLac(), cid.getCid(), cid.getPsc());
	if (result.getMcc() == CellTower.UNKNOWN)
		result.setMcc(cid.getMcc());
	if (result.getMnc() == CellTower.UNKNOWN)
		result.setMnc(cid.getMnc());
	if (result.getLac() == CellTower.UNKNOWN)
		result.setLac(cid.getLac());
	if (result.getCid() == CellTower.UNKNOWN)
		result.setCid(cid.getCid());
	if (result.getPsc() == CellTower.UNKNOWN)
		result.setPsc(cid.getPsc());
	this.put(result.getText(), result);
	this.put(result.getAltText(), result);
	result.setCellInfo(true);
	result.setDbm(cell.getCellSignalStrength().getDbm());
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
		result.setGeneration(2);
	result.setServing(cell.isRegistered());
	if ((result.getText() == null) && (result.getAltText() == null))
		Log.d(this.getClass().getSimpleName(), String.format("Added %d G cell with no data from CellInfoGsm", result.getGeneration()));
	return result;
}