Example usage for android.telephony SignalStrength getLevel

List of usage examples for android.telephony SignalStrength getLevel

Introduction

In this page you can find the example usage for android.telephony SignalStrength getLevel.

Prototype

public int getLevel() 

Source Link

Document

Retrieve an abstract level value for the overall signal strength.

Usage

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

/**
 * Originates from a change in signal strength
 * @param signalStrength SignalStrength/*from  ww w.  ja  v a 2  s. c om*/
 * @return JSON
 */
public static String signalStrengthJSON(SignalStrength signalStrength) {
    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    try {
        json.put("provider", SIGNAL_STRENGTH); // Yep provider and type are same values
        json.put("type", SIGNAL_STRENGTH);
        json.put("timestamp", calendar.getTimeInMillis());
        json.put("cdmaDbm", signalStrength.getCdmaDbm());
        json.put("cdmaEcio", signalStrength.getCdmaEcio());
        json.put("evdoDbm", signalStrength.getEvdoDbm());
        json.put("evdoEcio", signalStrength.getEvdoEcio());
        json.put("evdoSnr", signalStrength.getEvdoSnr());
        json.put("gsmBitErrorRate", signalStrength.getGsmBitErrorRate());
        json.put("gsmSignalStrength", signalStrength.getGsmSignalStrength());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            json.put("level", signalStrength.getLevel());
        }

        json.put("isGSM", signalStrength.isGsm());
    } catch (JSONException exc) {
        logJSONException(exc);
    }

    return json.toString();
}