Limo

mainactivity

Jun 22nd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package com.devstream.http;
  2.  
  3. import org.json.JSONArray;
  4. import org.json.JSONException;
  5. import org.json.JSONObject;
  6. import android.app.Activity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9.  
  10. public class MainActivity extends Activity {
  11. private static final String TAG = "MainActivity";
  12. private static final String URL = "http://10.0.2.2:8081/openmrs-standalone/ws/rest/v1/muzima/queueData";
  13.  
  14. @Override
  15. public void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.main);
  18.  
  19. // JSON object to hold the information, which is sent to the server
  20. JSONObject jsonObjSend = new JSONObject();
  21.  
  22. try {
  23.  
  24. // Add key/value pairs
  25. jsonObjSend.put("datasource", "3c023ab8-82ff-11e2-96ef-f0def12f7061");
  26. jsonObjSend.put("discriminator", "encounter");
  27. // Add a nested JSONObject (e.g. for header information)
  28. JSONObject payload = new JSONObject();
  29. JSONObject encounter= new JSONObject();
  30. JSONObject person= new JSONObject();
  31. JSONArray obs=new JSONArray();
  32. JSONObject o = new JSONObject();
  33. payload.put("person",person); // Device type
  34. payload.put("encounter",encounter);
  35. payload.put("obs",obs);
  36. obs.put(o);
  37. person.put("person.uuid","269857b6-f0b9-4c93-af4a-f18293679e89");
  38. encounter.put("form.uuid","fe9fc58f-d196-46cb-956d-f46445f558d9");
  39. encounter.put("encounterType.uuid","bdb58960-4d91-4ca7-a27a-8dabde40ec12");
  40. encounter.put("provider.uuid","3c023ab8-82ff-11e2-96ef-f0def12f7061");
  41. encounter.put("location.uuid","e1b1d9eb-69a2-4843-bccc-e73e33c70e4c");
  42. encounter.put("datetime","2013-06-17 00:00:00");
  43. o.put("uuid", "307AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
  44. o.put("type", "coded");
  45. o.put("value","1364AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. // Device OS version
  53. //header.put("language", "es-es"); // Language of the Android client
  54. jsonObjSend.put("payload", payload);
  55.  
  56. //Output the JSON object we're sending to Logcat:
  57. Log.i(TAG, jsonObjSend.toString(2));
  58.  
  59. } catch (JSONException e) {
  60. e.printStackTrace();
  61. }
  62.  
  63. // Send the HttpPostRequest and receive a JSONObject in return
  64. JSONObject jsonObjRecv = HttpClient.SendHttpPost(URL, jsonObjSend);
  65.  
  66.  
  67. /*
  68. * From here on do whatever you want with your JSONObject, e.g.
  69. * 1) Get the value for a key: jsonObjRecv.get("key");
  70. * 2) Get a nested JSONObject: jsonObjRecv.getJSONObject("key")
  71. * 3) Get a nested JSONArray: jsonObjRecv.getJSONArray("key")
  72. */
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment