Использую пуш-уведомления Urban для Android.При этом я хочу использовать трансляцию для отправки уведомлений всем моим пользователям.При использовании этого я получаю 400 ошибочных запросов.
Скажите, пожалуйста, что не так в моем коде:
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("sixxxxxxw","YSxxxxxxxxxx:Fxxxxxxxxxxxx".toCharArray());
}
});
URL url = new URL("https://go.urbanairship.com/api/airmail/send/broadcast/");
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type","application/json");
//connection.setRequestProperty("Content-Length", Integer.toString(data.length()));
JSONObject json = new JSONObject();
json.put("title","My title");
json.put("message","My message");
try {
output = connection.getOutputStream();
output.write(json.toString().getBytes());
} finally {
if (output != null) { output.close(); }
}
int status = ((HttpURLConnection) connection).getResponseCode();
System.out.println("status is..." + status);
Фактический JSON Payload
, который я хочу отправить:
{
"push": {
"aps": {
"alert": "New message!"
}
},
"title": "Message title",
"message": "Your full message here.",
"extra": {
"some_key": "some_value"
}
}
или также если у вас есть sample code for using urban airpship push notifications broadcast api
, пожалуйста, поделитесь здесь.
Как отправить payload
на обслуживание с помощью HttpsURLConnection.?
Спасибо