@Override protected void onHandleIntent(Intent intent) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); ApiAuthRest.setURLBase(URLBase); ApiAuthRest.setUsername(username); ApiAuthRest.setPassword(password); /*if (hasSubmittedToday("STEPS")) syncGoogleFit(2); else syncGoogleFit(1); if (hasSubmittedToday("CALORIES")) syncGoogleFit(4); else syncGoogleFit(3);*/ syncGoogleFit(1); syncGoogleFit(3); }
public void sendData() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); ApiAuthRest.setURLBase(Container.URLBase); ApiAuthRest.setUsername(Container.username); ApiAuthRest.setPassword(Container.password); Calendar c = Calendar.getInstance(); String date = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH) + " " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND); final String JSONHeight = "{\"obsDatetime\": \"" + date + "\"" + ", \"concept\": \"" + Container.height_uuid + "\"" + ", \"value\": \"" + Container.height + "\"" + ", \"person\": \"" + Container.user_uuid + "\"}"; final String JSONWeight = "{\"obsDatetime\": \"" + date + "\"" + ", \"concept\": \"" + Container.weight_uuid + "\"" + ", \"value\": \"" + Container.weight + "\"" + ", \"person\": \"" + Container.user_uuid + "\"}"; StringEntity heightV = null; StringEntity weightV = null; try { heightV = new StringEntity(JSONHeight); weightV = new StringEntity(JSONWeight); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } heightV.setContentType("application/json"); weightV.setContentType("application/json"); try { Log.i("OpenMRS response", "AddCalories = " + ApiAuthRest.getRequestPost("obs", heightV)); Log.i("OpenMRS response", "AddCalories = " + ApiAuthRest.getRequestPost("obs", weightV)); } catch (Exception e) { e.printStackTrace(); } }