registrationIds.add(device.getRegistrationId());
}
}
GcmMessage gcmMessage = (GcmMessage)pushMessage;
Sender sender = new Sender(Application.get().getAppContext().getGoogleServerApiKey());
Message.Builder messageBuilder = new Message.Builder();
if (StringUtils.isNotEmpty(gcmMessage.getCollapseKey())) {
messageBuilder.collapseKey(gcmMessage.getCollapseKey());
}
if (gcmMessage.isDelayWhileIdle() != null) {
messageBuilder.delayWhileIdle(gcmMessage.isDelayWhileIdle());
}
if (gcmMessage.getTimeToLive() != null) {
messageBuilder.timeToLive(gcmMessage.getTimeToLive());
}
for (Entry<String, String> entry : gcmMessage.getParameters().entrySet()) {
if (entry.getValue() != null) {
messageBuilder.addData(entry.getKey(), entry.getValue());
}
}
Message message = messageBuilder.build();
PushResponse pushResponse = new PushResponse();
try {
MulticastResult multicastResult = sender.send(message, Lists.newArrayList(registrationIds), 10);
// analyze the results
for (int i = 0; i < registrationIds.size(); i++) {
Result result = multicastResult.getResults().get(i);
Device device = devices.get(i);