if (tokens.isEmpty()) {
return;
}
List<String> registrationIDs = (List<String>) tokens;
final AndroidVariant androidVariant = (AndroidVariant) variant;
// payload builder:
Builder gcmBuilder = new Message.Builder();
// add the "recognized" keys...
gcmBuilder.addData("alert", pushMessage.getAlert());
gcmBuilder.addData("sound", pushMessage.getSound());
gcmBuilder.addData("badge", "" + pushMessage.getBadge());
// if present, apply the time-to-live metadata:
int ttl = pushMessage.getTimeToLive();
if (ttl != -1) {
gcmBuilder.timeToLive(ttl);
}
// iterate over the missing keys:
Set<String> keys = pushMessage.getData().keySet();
for (String key : keys) {
// GCM needs stringified values:
gcmBuilder.addData(key, "" + pushMessage.getData().get(key));
}
Message gcmMessage = gcmBuilder.build();
// send it out.....
try {
logger.log(Level.FINE, "Sending transformed GCM payload: " + gcmMessage);
Sender sender = cache.getSenderForAPIKey(androidVariant.getGoogleKey());
// GCM does only allow a 1000 device IDs
while (! registrationIDs.isEmpty()) {