Code example for JSONObject

Methods: put

0
     * 
     * @param batteryIntent the current battery information 
     * @return a JSONObject containing the battery status information 
     */ 
    private JSONObject getBatteryInfo(Intent batteryIntent) {
        JSONObject obj = new JSONObject();
        try { 
            obj.put("level", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0));
            obj.put("isPlugged", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_PLUGGED, -1) > 0 ? true : false);
        } catch (JSONException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } 
        return obj;
    } 
 
    /** 
     * Updates the JavaScript side whenever the battery changes 
     * 
     * @param batteryIntent the current battery information 
     * @return 
     */