Just in case, someone is trying to use the Google mechanism to send push notifications via urbanairhip to iOS devices, this is what finally helped me! This is for API V3.
import org.apache.commons.codec.binary.Base64; // commons-codec-1.6.jar
try {
URL url = new URL(URBAN_AIRSHIP_PUSH_URL);
String nameAndPassword = DEV_API_KEY+":"+DEV_API_MASTER_SECRET;
String authorizationHeader = Base64.encodeBase64String(nameAndPassword.getBytes("UTF-8"));
authorizationHeader = "Basic "+authorizationHeader;
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST);
request.addHeader(new HTTPHeader("Authorization", authorizationHeader));
request.addHeader(new HTTPHeader("Content-type", "application/json"));
request.addHeader(new HTTPHeader("Accept", "application/vnd.urbanairship+json; version=3;"));
logger.info("Authorization header for push:"+authorizationHeader);
logger.info("PushMessage payload:"+notificationPayload);
request.setPayload(notificationPayload.getBytes("UTF-8"));
URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
HTTPResponse fetchedResponse = urlFetchService.fetch(request);
if (fetchedResponse.getResponseCode() >= 400) {
logger.warning("Push notification failed:"+new String(fetchedResponse.getContent(), "UTF-8")+
"response code:"+fetchedResponse.getResponseCode());
} else {
logger.info("PushMessage send success");
}
} catch (MalformedURLException e) {
logger.log(Level.SEVERE, "PushMessage failed", e);
} catch (IOException e) {
logger.log(Level.SEVERE, "PushMessage failed", e);
}
Puran source
share