Skip to content

Commit

Permalink
Add android channel id support (#224)
Browse files Browse the repository at this point in the history
* Add android channel id support

* Add android channel id support
  • Loading branch information
chong-shao authored and hiranya911 committed Nov 29, 2018
1 parent ea9a28a commit b80bc92
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
that are helpful when debugging problems.
- [changed] Migrated the `FirebaseAuth` user management API to the
new Identity Toolkit endpoint.
- [added] Added new `setChannelId()` to the
AndroidNotification.Builder API for setting the Android
notification channel ID (new in Android O).

# v6.5.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class AndroidNotification {

@Key("title_loc_args")
private final List<String> titleLocArgs;

@Key("channel_id")
private final String channelId;

private AndroidNotification(Builder builder) {
this.title = builder.title;
Expand Down Expand Up @@ -93,6 +96,7 @@ private AndroidNotification(Builder builder) {
} else {
this.titleLocArgs = null;
}
this.channelId = builder.channelId;
}

/**
Expand All @@ -117,6 +121,7 @@ public static class Builder {
private List<String> bodyLocArgs = new ArrayList<>();
private String titleLocKey;
private List<String> titleLocArgs = new ArrayList<>();
private String channelId;

private Builder() {}

Expand Down Expand Up @@ -273,6 +278,20 @@ public Builder addAllTitleLocalizationArgs(@NonNull List<String> args) {
return this;
}

/**
* Sets the Android notification channel ID (new in Android O). The app must create a channel
* with this channel ID before any notification with this channel ID is received. If you
* don't send this channel ID in the request, or if the channel ID provided has not yet been
* created by the app, FCM uses the channel ID specified in the app manifest.
*
* @param channelId The notification's channel ID.
* @return This builder.
*/
public Builder setChannelId(String channelId) {
this.channelId = channelId;
return this;
}

/**
* Creates a new {@link AndroidNotification} instance from the parameters set on this builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ private static Map<Message, Map<String, Object>> buildTestMessages() {
.addAllTitleLocalizationArgs(ImmutableList.of("t-arg2", "t-arg3"))
.addBodyLocalizationArg("b-arg1")
.addAllBodyLocalizationArgs(ImmutableList.of("b-arg2", "b-arg3"))
.setChannelId("channel-id")
.build())
.build())
.setTopic("test-topic")
Expand All @@ -629,6 +630,7 @@ private static Map<Message, Map<String, Object>> buildTestMessages() {
.put("title_loc_args", ImmutableList.of("t-arg1", "t-arg2", "t-arg3"))
.put("body_loc_key", "test-body-key")
.put("body_loc_args", ImmutableList.of("b-arg1", "b-arg2", "b-arg3"))
.put("channel_id", "channel-id")
.build()
)
));
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/google/firebase/messaging/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void testAndroidMessageWithNotification() throws IOException {
.setBodyLocalizationKey("body-loc")
.addBodyLocalizationArg("body-arg1")
.addAllBodyLocalizationArgs(ImmutableList.of("body-arg2", "body-arg3"))
.setChannelId("channel-id")
.build())
.build())
.setTopic("test-topic")
Expand All @@ -163,6 +164,7 @@ public void testAndroidMessageWithNotification() throws IOException {
.put("title_loc_args", ImmutableList.of("title-arg1", "title-arg2", "title-arg3"))
.put("body_loc_key", "body-loc")
.put("body_loc_args", ImmutableList.of("body-arg1", "body-arg2", "body-arg3"))
.put("channel_id", "channel-id")
.build();
Map<String, Object> data = ImmutableMap.of(
"collapse_key", "test-key",
Expand Down

0 comments on commit b80bc92

Please sign in to comment.