June 2017
Intermediate to advanced
232 pages
5h 4m
English
The last step is implementing the custom request body. The request body represents the data the app sends, so it must have a structure compliant with the specification described previously (see the message structure described in the previous paragraphs). To do it, the app overrides the getBody() default method:
@Overridepublic byte[] getBody() throws AuthFailureError { Log.d(TAG, "Creating body..."); try { JSONObject jsonRequest = new JSONObject(); jsonRequest.put("sdid", deviceId); jsonRequest.put("ts", System.currentTimeMillis()); JSONObject data = new JSONObject(); data.put("Temperature", temp); data.put("Pressure", press); jsonRequest.put("data", data); String sData = jsonRequest.toString(); ...Read now
Unlock full access