Channel Groups API for Android SDK
Unsupported docs
PubNub no longer maintains Android SDK docs, but our Java SDK or Kotlin SDK are fully compatible with the Android platform and you can use them to build mobile apps, ensuring stable software development.
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. See Enable the features your app calls.
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.
1this.pubnub.addChannelsToChannelGroup()
2 .channelGroup(String)
3 .channels(Array)
Sample code
Add channels
1pubnub.addChannelsToChannelGroup()
2 .channelGroup("cg1")
3 .channels(Arrays.asList("ch1", "ch2", "ch3"))
4 .async(new PNCallback<PNChannelGroupsAddChannelResult>() {
5 @Override
6 public void onResponse(PNChannelGroupsAddChannelResult result, PNStatus status) {
7
8 }
9 });
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().
1{
2 "service" : "channel-registry",
3 "status" : 200,
4 "error" : false,
5 "message" : "OK"
6}
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. See Enable the features your app calls.
This function lists all channels in a channel group.
Method(s)
Use the following method in the Android SDK:
1pubnub.listChannelsForChannelGroup()
2 .channelGroup(String)
Sample code
List channels
1pubnub.listChannelsForChannelGroup()
2 .channelGroup("cg1")
3 .async(new PNCallback<PNChannelGroupsAllChannelsResult>() {
4 @Override
5 public void onResponse(PNChannelGroupsAllChannelsResult result, PNStatus status) {
6
7 }
8 });
Returns
The listChannelsForChannelGroup() operation returns a PNChannelGroupsAllChannelsResult which contains the following operations:
getChannels()#- List of
channelsof achannel 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. See Enable the features your app calls.
This function removes channels from a channel group.
Method(s)
Use the following method in the Android SDK:
1pubnub.removeChannelsFromChannelGroup()
2 .channelGroup(String)
3 .channels(Array)
Sample code
Remove channels
1pubnub.removeChannelsFromChannelGroup()
2 .channelGroup("family")
3 .channels(Arrays.asList("son"))
4 .async(new PNCallback<PNChannelGroupsRemoveChannelResult>() {
5 @Override
6 public void onResponse(PNChannelGroupsRemoveChannelResult result, PNStatus status) {
7
8 }
9 });
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().
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}
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. See Enable the features your app calls.
This function deletes a channel group.
Method(s)
Use the following method in the Android SDK:
1pubnub.deleteChannelGroup()
2 .channelGroup(String)
Sample code
Delete channel group
1pubnub.deleteChannelGroup()
2 .channelGroup("family")
3 .async(new PNCallback<PNChannelGroupsDeleteGroupResult>() {
4 @Override
5 public void onResponse(PNChannelGroupsDeleteGroupResult result, PNStatus status) {
6
7 }
8 });
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().
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}