I have a Java web server which I want to send UA push notifications through. I know this is possible through UA's dashboard, but I want to communicate with UA using the web-server directly.
I have already read this documentation, and have reviewed this SO question, but am still at a bit of a loss for where to start.
Can anyone please help point me toward a good starting point? Do I need to import any specific .jar files, etc?
I have been trying to adapt the following code snippet, but it doesn't seem to function properly. What am I doing wrong?
URL mURL=new URL("https://go.urbanairship.com/api/push/broadcast");
HttpsURLConnection connection = (HttpsURLConnection)mURL.openConnection();
connection.setRequestMethod("POST");
JSONObject mPayload=new JSONObject();
JSONObject mPayload1=new JSONObject();
JSONObject mPayload2=new JSONObject();
mPayload1.put("extra", mPayload2);
mPayload1.put("alert", "hello world");
mPayload2.put("phonenumber", "12345");
mPayload.put("android", mPayload1);
System.out.println(mPayload.toString());
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.addRequestProperty("Content-Type","application/json;charset=UTF-8");
String authString = "**MY APP KEY**" + ":" + "**MASTER KEY**";
String authStringBase64 = new String(Base64.encodeBytes(authString.getBytes()));
authStringBase64 = authStringBase64.trim();
connection.addRequestProperty("Authorization", "Basic " + authStringBase64);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.write(mPayload.toString().getBytes());
wr.flush();
Log.d("print", "response code"+ connection.getResponseCode());