diff --git a/client-libraries/java/rest-client/src/com/google/android/gcm/server/Constants.java b/client-libraries/java/rest-client/src/com/google/android/gcm/server/Constants.java index a499e78..357f7cc 100644 --- a/client-libraries/java/rest-client/src/com/google/android/gcm/server/Constants.java +++ b/client-libraries/java/rest-client/src/com/google/android/gcm/server/Constants.java @@ -77,6 +77,11 @@ public final class Constants { */ public static final String PARAM_PRIORITY = "priority"; + /** + * Parameter used to set the content available (iOS only) + */ + public static final String PARAM_CONTENT_AVAILABLE = "content_available"; + /** * Value used to set message priority to normal. */ diff --git a/client-libraries/java/rest-client/src/com/google/android/gcm/server/Message.java b/client-libraries/java/rest-client/src/com/google/android/gcm/server/Message.java index d9f6fd7..99012c1 100644 --- a/client-libraries/java/rest-client/src/com/google/android/gcm/server/Message.java +++ b/client-libraries/java/rest-client/src/com/google/android/gcm/server/Message.java @@ -66,8 +66,10 @@ public final class Message implements Serializable { private final Boolean dryRun; private final String restrictedPackageName; private final String priority; + private final Boolean contentAvailable; private final Notification notification; + public enum Priority { NORMAL, HIGH } @@ -83,6 +85,7 @@ public static final class Builder { private Boolean dryRun; private String restrictedPackageName; private String priority; + private Boolean contentAvailable; private Notification notification; public Builder() { @@ -160,6 +163,14 @@ public Builder notification(Notification value) { return this; } + /** + * Sets the contentAvailable property + */ + public Builder contentAvailable(Boolean value){ + contentAvailable = value; + return this; + } + public Message build() { return new Message(this); } @@ -174,6 +185,7 @@ private Message(Builder builder) { dryRun = builder.dryRun; restrictedPackageName = builder.restrictedPackageName; priority = builder.priority; + contentAvailable = builder.contentAvailable; notification = builder.notification; } @@ -219,6 +231,13 @@ public String getPriority() { return priority; } + /** + * Gets the contentAvailable value + */ + public Boolean getContentAvailable() { + return contentAvailable; + } + /** * Gets the payload data, which is immutable. */ @@ -239,6 +258,9 @@ public String toString() { if (priority != null) { builder.append("priority=").append(priority).append(", "); } + if (contentAvailable != null){ + builder.append("contentAvailable=").append(contentAvailable).append(", "); + } if (collapseKey != null) { builder.append("collapseKey=").append(collapseKey).append(", "); } diff --git a/client-libraries/java/rest-client/src/com/google/android/gcm/server/Sender.java b/client-libraries/java/rest-client/src/com/google/android/gcm/server/Sender.java index 59713e4..25b1f3b 100644 --- a/client-libraries/java/rest-client/src/com/google/android/gcm/server/Sender.java +++ b/client-libraries/java/rest-client/src/com/google/android/gcm/server/Sender.java @@ -43,6 +43,7 @@ import static com.google.android.gcm.server.Constants.PARAM_DELAY_WHILE_IDLE; import static com.google.android.gcm.server.Constants.PARAM_DRY_RUN; import static com.google.android.gcm.server.Constants.PARAM_PRIORITY; +import static com.google.android.gcm.server.Constants.PARAM_CONTENT_AVAILABLE; import static com.google.android.gcm.server.Constants.PARAM_RESTRICTED_PACKAGE_NAME; import static com.google.android.gcm.server.Constants.PARAM_TIME_TO_LIVE; import static com.google.android.gcm.server.Constants.TOKEN_CANONICAL_REG_ID; @@ -456,6 +457,7 @@ private void messageToMap(Message message, Map mapRequest) { return; } setJsonField(mapRequest, PARAM_PRIORITY, message.getPriority()); + setJsonField(mapRequest, PARAM_CONTENT_AVAILABLE, message.getContentAvailable()); setJsonField(mapRequest, PARAM_TIME_TO_LIVE, message.getTimeToLive()); setJsonField(mapRequest, PARAM_COLLAPSE_KEY, message.getCollapseKey()); setJsonField(mapRequest, PARAM_RESTRICTED_PACKAGE_NAME, message.getRestrictedPackageName()); diff --git a/client-libraries/java/rest-client/test/com/google/android/gcm/server/MessageTest.java b/client-libraries/java/rest-client/test/com/google/android/gcm/server/MessageTest.java index 53ff13d..b4e2ac7 100644 --- a/client-libraries/java/rest-client/test/com/google/android/gcm/server/MessageTest.java +++ b/client-libraries/java/rest-client/test/com/google/android/gcm/server/MessageTest.java @@ -48,6 +48,7 @@ public void testRequiredParameters() { public void testOptionalParameters() { Message message = new Message.Builder() .priority(Message.Priority.HIGH) + .contentAvailable(true) .collapseKey("108") .delayWhileIdle(true) .timeToLive(42) @@ -59,6 +60,7 @@ public void testOptionalParameters() { .notification(new Notification.Builder("my").build()) .build(); assertEquals("high", message.getPriority()); + assertTrue(message.getContentAvailable()); assertEquals("108", message.getCollapseKey()); assertTrue(message.isDelayWhileIdle()); assertEquals(42, message.getTimeToLive().intValue()); @@ -70,6 +72,7 @@ public void testOptionalParameters() { assertEquals("v2", data.get("k2")); String toString = message.toString(); assertTrue(toString.contains("priority=high")); + assertTrue(toString.contains("contentAvailable=true")); assertTrue(toString.contains("collapseKey=108")); assertTrue(toString.contains("timeToLive=42")); assertTrue(toString.contains("delayWhileIdle=true"));