Example usage for android.telephony CellIdentityWcdma getLac

List of usage examples for android.telephony CellIdentityWcdma getLac

Introduction

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

Prototype

public int getLac() 

Source Link

Usage

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

/**
 * Converts CellInfoWcdma into JSON//from   ww w.  ja  va 2s . c  o  m
 * Some devices may not work correctly:
 * - Reference 1: https://code.google.com/p/android/issues/detail?id=191492
 * - Reference 2: http://stackoverflow.com/questions/17815062/cellidentitygsm-on-android
 * @param cellInfo CellInfoWcdma
 * @return JSON
 */
public static String cellInfoWCDMAJSON(CellInfoWcdma cellInfo, boolean returnSignalStrength) {

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo != null) {
        try {
            json.put("provider", CELLINFO_PROVIDER);
            json.put("type", WCDMA);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityWcdma identityWcdma = cellInfo.getCellIdentity();

            json.put("cid", identityWcdma.getCid());
            json.put("lac", identityWcdma.getLac());
            json.put("mcc", identityWcdma.getMcc());
            json.put("mnc", identityWcdma.getMnc());
            json.put("psc", identityWcdma.getPsc());

            if (returnSignalStrength) {
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthWcdma.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthWcdma.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthWcdma.getLevel());

                json.put("cellSignalStrengthWcdma", jsonSignalStrength);
            }
        } catch (JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}

From source file:org.pixmob.freemobile.netstat.MonitorService.java

/**
 * Check if we are connected on a Free Mobile femtocell
 *//*w  w  w  .  jav  a 2s.c  om*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void updateFemtocellStatus() {
    // No need to check LAC if current operator is not free mobile
    // And no need to check if network type is not femtocell supported network
    if ((!MobileOperator.FREE_MOBILE.equals(MobileOperator.fromString(mobileOperatorId)))
            || ((MobileOperator.FREE_MOBILE.equals(MobileOperator.fromString(mobileOperatorId)))
                    && (!FEMTOCELL_AVAILABLE_NETWORK_TYPE.contains(mobileNetworkType)))) {
        isFemtocell = false;
        return;
    }

    Integer lac = null;
    if (tm != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

            //get the cell list
            List<CellInfo> cellInfos = tm.getAllCellInfo();
            if (cellInfos != null) {
                for (CellInfo cellInfo : cellInfos) {

                    if (cellInfo.isRegistered()) { //we use only registered cells
                        if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
                                && (cellInfo instanceof CellInfoWcdma)) { //manage the wcdma cell case
                            Log.d(TAG, "We got a WCDMA cell");
                            CellIdentityWcdma ci = ((CellInfoWcdma) cellInfo).getCellIdentity();
                            if (ci != null) { //save the LAC and exit loop
                                lac = ci.getLac();
                                Log.d(TAG, "We got the LAC - exit loop");
                                break;
                            }

                        } else if (cellInfo instanceof CellInfoGsm) { //test the gsm case
                            CellIdentityGsm ci = ((CellInfoGsm) cellInfo).getCellIdentity();
                            Log.d(TAG, "We got a CDMA cell");
                            if (ci != null) { //save the LAC and exit loop
                                lac = ci.getLac();
                                Log.d(TAG, "We got the LAC - exit loop");
                                break;
                            }
                        }

                    } else
                        Log.d(TAG, "Unregistered cell - skipping");
                }
            } else
                Log.d(TAG, "No cell infos available");

        }
        if (lac == null) { //use old API if LAC was not found with the new method (useful for buggy devices such as Samsung Galaxy S5) or if SDK is too old
            CellLocation cellLocation = tm.getCellLocation(); //cell location might be null... handle with care
            if ((cellLocation != null) && (cellLocation instanceof GsmCellLocation)) {
                Log.d(TAG, "We got a old GSM cell with LAC");
                lac = ((GsmCellLocation) cellLocation).getLac();
            }
        }
    }
    if (DEBUG)
        Log.d(TAG, "LAC value : " + lac);

    Log.i(TAG, "Femtocell value : " + isFemtocell);

    if (lac != null) {
        String lacAsString = String.valueOf(lac);
        isFemtocell = (lacAsString.length() == 4)
                && (lacAsString.subSequence(1, 3).equals(FREE_MOBILE_FEMTOCELL_LAC_CODE));
    }
}