Example usage for android.telephony.gsm GsmCellLocation getLac

List of usage examples for android.telephony.gsm GsmCellLocation getLac

Introduction

In this page you can find the example usage for android.telephony.gsm GsmCellLocation getLac.

Prototype

public int getLac() 

Source Link

Usage

From source file:Main.java

public static int getLat(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();

    return cellLocation == null ? -1 : cellLocation.getLac();
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonCellLocation(CellLocation cellLocation) throws JSONException {
    JSONObject result = new JSONObject();
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation location = (GsmCellLocation) cellLocation;
        result.put("lac", location.getLac());
        result.put("cid", location.getCid());
    }/*from w ww  . ja v a2 s  .  c  om*/
    // TODO(damonkohler): Add support for CdmaCellLocation. Not supported until API level 5.
    return result;
}

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Parses data from PhoneStateListener.LISTEN_CELL_LOCATION.onCellLocationChanged
 * http://developer.android.com/reference/android/telephony/cdma/CdmaCellLocation.html
 * @param location GsmCellLocation//  w w w. j  a va 2  s .  c  om
 * @return JSON
 */
public static String gsmCellLocationJSON(GsmCellLocation location) {

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    if (location != null) {
        try {
            json.put("provider", CELLLOCATION_PROVIDER);
            json.put("type", GSM);
            json.put("timestamp", calendar.getTimeInMillis());
            json.put("cid", location.getCid());
            json.put("lac", location.getLac());
            json.put("psc", location.getPsc());
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}

From source file:com.wbtech.common.CommonUtil.java

/**
 * ??/*from   ww  w .j a  va 2s  .c om*/
 * @throws Exception
 */
public static SCell getCellInfo(Context context) throws Exception {
    SCell cell = new SCell();
    /** API?? */
    TelephonyManager mTelNet = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = (GsmCellLocation) mTelNet.getCellLocation();
    if (location == null) {
        if (UmsConstants.DebugMode) {
            Log.e("GsmCellLocation Error", "GsmCellLocation is null");
        }
        return null;
    }

    String operator = mTelNet.getNetworkOperator();
    //        System.out.println("operator------>"+operator.toString());
    int mcc = Integer.parseInt(operator.substring(0, 3));
    int mnc = Integer.parseInt(operator.substring(3));
    int cid = location.getCid();
    int lac = location.getLac();

    /** ? */
    cell.MCC = mcc;
    cell.MCCMNC = Integer.parseInt(operator);
    cell.MNC = mnc;
    cell.LAC = lac;
    cell.CID = cid;

    return cell;
}

From source file:pk.development.sms.detection.CellSniffer.java

@Override
public void onCellLocationChanged(CellLocation location) {

    switch (teleManager.getPhoneType()) {
    case TelephonyManager.PHONE_TYPE_GSM:
        GsmCellLocation gsmCellData = (GsmCellLocation) teleManager.getCellLocation();
        if (gsmCellData != null) {
            btsData.setLac(gsmCellData.getLac());
            btsData.setCid(gsmCellData.getCid());
            btsData.setRoaming(teleManager.isNetworkRoaming());
            btsData.setBtsType(BtsType.GSM);

            String networkProvider = teleManager.getNetworkOperator();
            if (!TextUtils.isEmpty(networkProvider)) {
                btsData.setMcc(Integer.parseInt(networkProvider.substring(0, 3)));
                btsData.setMnc(Integer.parseInt(networkProvider.substring(3)));
            }//ww  w .  j ava 2 s  .com
        }
        break;
    case TelephonyManager.PHONE_TYPE_CDMA:
        CdmaCellLocation cdmaCellData = (CdmaCellLocation) teleManager.getCellLocation();
        if (cdmaCellData != null) {
            btsData.setLac(cdmaCellData.getNetworkId());
            btsData.setCid(cdmaCellData.getBaseStationId());
            btsData.setBtsType(BtsType.CDMA);
        }
        break;
    }
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellLocationChannel.java

@Override
protected boolean startPoll() {
    if (telephony != null) {
        CellLocation loc = telephony.getCellLocation();
        JSONObject value = new JSONObject();
        try {// w  ww. j a  va 2s.c om
            value.put("timestamp", System.currentTimeMillis());
            if (loc instanceof GsmCellLocation) {
                GsmCellLocation gsm = (GsmCellLocation) loc;
                if (gsm.getCid() != (-1))
                    value.put("cid", gsm.getCid());
                if (gsm.getLac() != (-1))
                    value.put("lac", gsm.getLac());
                value.put("type", "gsm");
            } else if (loc instanceof CdmaCellLocation) {
                CdmaCellLocation cdma = (CdmaCellLocation) loc;
                if (cdma.getBaseStationId() != (-1))
                    value.put("baseStationId", cdma.getBaseStationId());
                if (cdma.getBaseStationLatitude() != Integer.MAX_VALUE)
                    value.put("baseStationLat", cdma.getBaseStationLatitude());
                if (cdma.getBaseStationLongitude() != Integer.MAX_VALUE)
                    value.put("baseStationLon", cdma.getBaseStationLongitude());
                if (cdma.getNetworkId() != (-1))
                    value.put("baseStationId", cdma.getNetworkId());
                if (cdma.getNetworkId() != (-1))
                    value.put("networkId", cdma.getNetworkId());
                if (cdma.getSystemId() != (-1))
                    value.put("systemId", cdma.getSystemId());
                value.put("type", "cdma");
            } else if (loc != null) {
                value.put("type", loc.getClass().getName());
            }
            if (includeNeighbours) {
                List<NeighboringCellInfo> neighbors = telephony.getNeighboringCellInfo();
                JSONArray ns = new JSONArray();
                value.put("neighbors", ns);
                for (NeighboringCellInfo neighbor : neighbors) {
                    JSONObject n = new JSONObject();
                    if (neighbor.getCid() != (-1))
                        n.put("cid", neighbor.getCid());
                    if (neighbor.getLac() != (-1))
                        n.put("lac", neighbor.getLac());
                    n.put("networkType", neighbor.getNetworkType());
                    n.put("rssi", neighbor.getRssi());
                    ns.put(n);
                }
            }
        } catch (JSONException e) {
            // shouldn't
        }
        onNewValue(value);
    }
    return false;
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellStrengthChannel.java

protected void update(CellLocation loc, SignalStrength ss) {
    if (loc == null && telephony != null)
        loc = telephony.getCellLocation();
    // TODO Auto-generated method stub
    JSONObject value = new JSONObject();
    try {/*from  ww w . jav  a  2  s.  c o  m*/
        value.put("timestamp", System.currentTimeMillis());
        if (loc instanceof GsmCellLocation) {
            GsmCellLocation gsm = (GsmCellLocation) loc;
            if (gsm.getCid() != (-1))
                value.put("cid", gsm.getCid());
            if (gsm.getLac() != (-1))
                value.put("lac", gsm.getLac());
            value.put("type", "gsm");
        } else if (loc instanceof CdmaCellLocation) {
            CdmaCellLocation cdma = (CdmaCellLocation) loc;
            if (cdma.getBaseStationId() != (-1))
                value.put("baseStationId", cdma.getBaseStationId());
            if (cdma.getBaseStationLatitude() != Integer.MAX_VALUE)
                value.put("baseStationLat", cdma.getBaseStationLatitude());
            if (cdma.getBaseStationLongitude() != Integer.MAX_VALUE)
                value.put("baseStationLon", cdma.getBaseStationLongitude());
            if (cdma.getNetworkId() != (-1))
                value.put("baseStationId", cdma.getNetworkId());
            if (cdma.getNetworkId() != (-1))
                value.put("networkId", cdma.getNetworkId());
            if (cdma.getSystemId() != (-1))
                value.put("systemId", cdma.getSystemId());
            value.put("type", "cdma");
        } else if (loc != null) {
            value.put("type", loc.getClass().getName());
        }

        if (ss != null) {
            if (ss.getCdmaDbm() != (-1))
                value.put("cdmsDbm", ss.getCdmaDbm());
            if (ss.getCdmaEcio() != (-1))
                value.put("cdmaEcio", ss.getCdmaEcio());
            if (ss.getEvdoDbm() != (-1))
                value.put("evdoDbm", ss.getEvdoDbm());
            if (ss.getEvdoEcio() != (-1))
                value.put("evdiEcio", ss.getEvdoEcio());
            if (ss.getEvdoSnr() != (-1))
                value.put("evdoSnr", ss.getEvdoSnr());
            if (ss.getGsmBitErrorRate() != (-1))
                value.put("gsmBER", ss.getGsmBitErrorRate());
            if (ss.getGsmSignalStrength() != (-1))
                value.put("gsmSS", ss.getGsmSignalStrength());
            value.put("gsm", ss.isGsm());
        }
    } catch (JSONException e) {
        // shouldn't
    }
    onNewValue(value);
}

From source file:org.kaaproject.kaa.demo.cellmonitor.CellMonitorFragment.java

private void updateGsmCellLocation() {
    int cid = UNDEFINED;
    int lac = UNDEFINED;
    CellLocation cellLocation = mApplication.getCellLocation();
    if (cellLocation != null && cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
        cid = gsmCellLocation.getCid();/* w  ww . j a v  a 2s.  c o  m*/
        lac = gsmCellLocation.getLac();
    }
    if (cid != UNDEFINED) {
        mGsmCellIdValue.setText(String.valueOf(cid));
    } else {
        mGsmCellIdValue.setText(R.string.unavailable);
    }
    if (lac != UNDEFINED) {
        mGsmLacValue.setText(String.valueOf(lac));
    } else {
        mGsmLacValue.setText(R.string.unavailable);
    }
}

From source file:org.most.input.CellInput.java

@Override
public void workToDo() {
    CellLocation cellLocation = _telephonyManager.getCellLocation();
    _telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
    nciList = _telephonyManager.getNeighboringCellInfo();
    DataBundle b = _bundlePool.borrowBundle();
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmLocation = (GsmCellLocation) cellLocation;
        b.putInt(KEY_GSM_CELL_ID, gsmLocation.getCid());
        b.putInt(KEY_GSM_LAC, gsmLocation.getLac());
        b.putInt(KEY_RSSI, _phoneStateListener.signalStrengthValue);
        // gsmLocation.getPsc() require api 9
        // b.putInt(KEY_GSM_PSC, gsmLocation.getPsc());
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_GSM);
    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) cellLocation;
        b.putInt(KEY_BASE_STATION_ID, cdmaLocation.getBaseStationId());
        b.putInt(KEY_BASE_STATION_LATITUDE, cdmaLocation.getBaseStationLatitude());
        b.putInt(KEY_BASE_STATION_LONGITUDE, cdmaLocation.getBaseStationLongitude());
        b.putInt(KEY_BASE_NETWORK_ID, cdmaLocation.getNetworkId());
        b.putInt(KEY_BASE_SYSTEM_ID, cdmaLocation.getSystemId());
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_CDMA);
    } else {//  w w  w. j  a v a2  s .  com
        b.putInt(KEY_PHONE_TYPE, TelephonyManager.PHONE_TYPE_NONE);
    }
    b.putLong(Input.KEY_TIMESTAMP, System.currentTimeMillis());
    b.putInt(Input.KEY_TYPE, Input.Type.CELL.toInt());
    post(b);
    postResults(b, nciList);
    scheduleNextStart();
}

From source file:ru.dublgis.androidhelpers.mobility.CellListener.java

private void reportData() {
    if (ActivityCompat.checkSelfPermission(getContext(), ACCESS_FINE_LOCATION) != PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getContext(), ACCESS_COARSE_LOCATION) != PERMISSION_GRANTED) {
        return;/*  ww w.j av a 2 s  . com*/
    }

    int dbm = 99;
    boolean gsm = false;

    synchronized (TAG) {
        gsm = mSignalStrengthLast.isGsm();
        dbm = gsm ? getGsmDbm(mSignalStrengthLast.getGsmSignalStrength()) : mSignalStrengthLast.getCdmaDbm();
    }

    CellLocation loc = mManager.getCellLocation();

    if (gsm && loc instanceof GsmCellLocation) {
        GsmCellLocation locGsm = (GsmCellLocation) loc;
        cellUpdate(native_ptr_, "gsm", locGsm.getCid(), // gsm cell id, -1 if unknown, 0xffff max legal value
                locGsm.getLac(), // gsm location area code, -1 if unknown, 0xffff max legal value
                Integer.MAX_VALUE, Integer.MAX_VALUE, dbm, Integer.MAX_VALUE);
    } else if (loc instanceof CdmaCellLocation) {
        CdmaCellLocation locCdma = (CdmaCellLocation) loc;
        cellUpdate(native_ptr_, "cdma", locCdma.getBaseStationId(), // cdma base station identification number, -1 if unknown
                locCdma.getNetworkId(), // cdma network identification number, -1 if unknown
                Integer.MAX_VALUE, Integer.MAX_VALUE, dbm, Integer.MAX_VALUE);
    }
}