Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. //final String REGISTRATIONS_ID = "APA91bGgs7g-iF1kEfo_Y5v-iU3IZRW5dODsRLL3nx7YrRy-Y46oUreSMDzUV8KEs61lBjA_GlaEwAN6Mr-kfH_N2kdLtsP2OQsLKr4r9mfweVelaM0u7LC_HsMyRce-F2JaO2wtxFAGXZMlD76pHZ9XEywdIdKhUCvjB5ErO-8Y67lGVICiZb8";
  2. final String REGISTRATIONS_ID = "APA91bH6pvkDTKnkIw6RvKjjJYk5cV3l7tvGOE8Mkiq8sCoGbOMXSVjs8Kyn40dv8zTzovQuDv4Ub-0xhRavTguqOWxyZCm0nk4Nn1wIfL5nP-xq1cT3j-jbHmKgzjE49KP7Cd0lQ3-mIVHhRPGRukOljOQySCITxXYMyROLbYd8mEM_929aG1I";
  3.  
  4.  
  5. // create JSON request
  6. // reference: https://developer.android.com/google/gcm/http.html#request
  7. JSONObject jsonRequest = new JSONObject();
  8. try {
  9.  
  10. // JSON Array of registrations ids (patient's devices)
  11. // we get registration IDs from database
  12. JSONArray regIds = new JSONArray();
  13. regIds.put(REGISTRATIONS_ID);
  14.  
  15. // JSON message
  16. JSONObject message = new JSONObject();
  17. message.put("notification", "1");
  18. message.put("action", "out_of_bounds");
  19.  
  20. // put into JSON request
  21. jsonRequest.put("registration_ids", regIds);
  22. jsonRequest.put("data", message);
  23. } catch (JSONException e) {
  24. e.printStackTrace();
  25. }
  26.  
  27. System.out.println(jsonRequest.toString());
  28. System.out.println();
  29.  
  30. // Send
  31. GCMSender gcm = new GCMSender();
  32.  
  33. String response = gcm.send(jsonRequest);
  34.  
  35. System.out.println(gcm.getStatusCode());
  36. System.out.println(response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement