Example usage for android.telephony CellSignalStrengthWcdma getDbm

List of usage examples for android.telephony CellSignalStrengthWcdma getDbm

Introduction

In this page you can find the example usage for android.telephony CellSignalStrengthWcdma getDbm.

Prototype

@Override
public int getDbm() 

Source Link

Document

Get the RSCP as dBm value -120..-24dBm or CellInfo#UNAVAILABLE UNAVAILABLE .

Usage

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

/**
 * Converts CellInfoWcdma into JSON/*  w w  w  .  j  a v a2s  . co  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();
}