Channel Groups API for Android SDK
Channel groups allow PubNub developers to bundle thousands of channels into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.
Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
Add channels to a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the PubNub Admin Portal. Read the support page on enabling add-on features on your keys.
This function adds channels to a channel group.
Method(s)
Use the following method in the Android SDK:
Maximum number of channels
You can add up to 200 channels to a channel group per API call.
this.pubnub.addChannelsToChannelGroup()
.channelGroup(String)
.channels(Array)
| Parameter | Description |
|---|---|
channelGroup *Type: String | The channel group to add the channels to. |
channels *Type: Array | The channels to add to the channel group. |
async *Type: PNCallback | PNCallback of type PNChannelGroupsAddChannelResult |
Sample code
Add channels
pubnub.addChannelsToChannelGroup()
.channelGroup("cg1")
.channels(Arrays.asList("ch1", "ch2", "ch3"))
.async(new PNCallback<PNChannelGroupsAddChannelResult>() {
@Override
public void onResponse(PNChannelGroupsAddChannelResult result, PNStatus status) {
}
});
Response
The addChannelsToChannelGroup() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().
{
"service" : "channel-registry",
"status" : 200,
"error" : false,
"message" : "OK"
}
List channels in a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function lists all channels in a channel group.
Method(s)
Use the following method in the Android SDK:
pubnub.listChannelsForChannelGroup()
.channelGroup(String)
| Parameter | Description |
|---|---|
channelGroup *Type: String | The channel group for which to list channels. |
async *Type: PNCallback | PNCallback of type PNChannelGroupsAllChannelsResult. |
Sample code
List channels
pubnub.listChannelsForChannelGroup()
.channelGroup("cg1")
.async(new PNCallback<PNChannelGroupsAllChannelsResult>() {
@Override
public void onResponse(PNChannelGroupsAllChannelsResult result, PNStatus status) {
}
});
Returns
The listChannelsForChannelGroup() operation returns a PNChannelGroupsAllChannelsResult which contains the following operations:
| Method | Description |
|---|---|
getChannels()Type: List <String> | List of channels of a channel group. |
Remove channels from a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes channels from a channel group.
Method(s)
Use the following method in the Android SDK:
pubnub.removeChannelsFromChannelGroup()
.channelGroup(String)
.channels(Array)
| Parameter | Description |
|---|---|
channels *Type: Array | The channels to remove from the channel group. |
channelGroup *Type: String | The channel group from which to remove the channels. |
asyncType: PNCallback | PNCallback of type PNChannelGroupsRemoveChannelResult. |
Sample code
Remove channels
pubnub.removeChannelsFromChannelGroup()
.channelGroup("family")
.channels(Arrays.asList("son"))
.async(new PNCallback<PNChannelGroupsRemoveChannelResult>() {
@Override
public void onResponse(PNChannelGroupsRemoveChannelResult result, PNStatus status) {
}
});
Response
The removeChannelsFromChannelGroup() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}
Delete a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function deletes a channel group.
Method(s)
Use the following method in the Android SDK:
pubnub.deleteChannelGroup()
.channelGroup(String)
| Parameter | Description |
|---|---|
channelGroup *Type: String | The channel group to delete. |
asyncType: PNCallback | PNCallback of type PNChannelGroupsDeleteGroupResult. |
Sample code
Delete channel group
pubnub.deleteChannelGroup()
.channelGroup("family")
.async(new PNCallback<PNChannelGroupsDeleteGroupResult>() {
@Override
public void onResponse(PNChannelGroupsDeleteGroupResult result, PNStatus status) {
}
});
Response
The deleteChannelGroup() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}