App Context 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.

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.

PubNub also triggers events when object data is changed: set, updated, or removed from the database. Making a request to set the same data that already exists doesn't trigger an event. Clients can receive these events in real time and update their front-end application accordingly.

User​

Get metadata for all users​

Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

To Get All UUID Metadata you can use the following method(s) in the Android SDK:

1pubnub.getAllUUIDMetadata()
2 .limit(Integer)
3 .page(PNPage)
4 .filter(String)
5 .sort(List<PNSortKey>)
6 .includeTotalCount(Boolean)
7 .includeCustom(Boolean)
* required
ParameterDescription
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String?
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
n/a
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.

Sample code​

1pubnub.getAllUUIDMetadata()
2 .limit(20)
3 .sort(SortKey.asc(SortKey.Key.ID), SortKey.desc(SortKey.Key.UPDATED))
4 .includeTotalCount(true)
5 .includeCustom(true)
6 .async(new PNCallback<PNGetAllUUIDMetadataResult>() {
7 @Override
8 public void onResponse(@Nullable final PNGetAllUUIDMetadataResult result, @NotNull final PNStatus status) {
9 if (status.isError()) {
10 //handle error
11 }
12 else {
13 //handle result
14 }
15 }
show all 16 lines

Response​

1public class PNGetAllUUIDMetadataResult extends EntityArrayEnvelope<PNUUIDMetadata> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNUUIDMetadata> data;
7 PNPage nextPage() {
8 return PNPage.next(next);
9 }
10 PNPage previousPage() {
11 return PNPage.previous(prev);
12 }
13}
14
15public class PNUUIDMetadata extends PNObject {
show all 24 lines

Get user metadata​

Returns metadata for the specified UUID, optionally including the custom data object for each.

Method(s)​

To Get UUID Metadata you can use the following method(s) in the Android SDK:

1pubnub.getUUIDMetadata()
2 .uuid(String)
3 .includeCustom(Boolean)
* required
ParameterDescription
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.

Sample code​

1pubnub.getUUIDMetadata().async(new PNCallback<PNGetUUIDMetadataResult>() {
2 @Override
3 public void onResponse(@Nullable final PNGetUUIDMetadataResult result, @NotNull final PNStatus status) {
4 if (status.isError()) {
5 //handle error
6 }
7 else {
8 //handle result
9 }
10 }
11});

Response​

1public class PNGetUUIDMetadataResult extends EntityEnvelope<PNUUIDMetadata> {
2 int status;
3 PNUUIDMetadata data;
4}
5
6public class PNUUIDMetadata extends PNObject {
7 String id;
8 Object custom;
9 String updated;
10 String eTag;
11 String name;
12 String email;
13 String externalId;
14 String profileUrl;
15}

Set user metadata​

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a UUID in the database, optionally including the custom data object for each.

Method(s)​

To Set UUID Metadata you can use the following method(s) in the Android SDK:

1pubnub.setUUIDMetadata()
2 .uuid(String)
3 .name(String)
4 .externalId(String)
5 .profileUrl(String)
6 .email(String)
7 .custom(Map<String, Object>)
8 .includeCustom(true)
* required
ParameterDescription
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.
name
Type: String
Default:
n/a
Display name for the user.
externalId
Type: String
Default:
n/a
User's identifier in an external system.
profileUrl
Type: String
Default:
n/a
The URL of the user's profile picture.
email
Type: String
Default:
n/a
The user's email address.
custom
Type: Any
Default:
n/a
Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn’t supported.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Sample code​

1pubnub.setUUIDMetadata()
2 .name("Foo")
3 .profileUrl("http://example.com")
4 .email("foo@example.com")
5 .includeCustom(true)
6 .async(new PNCallback<PNSetUUIDMetadataResult>() {
7 @Override
8 public void onResponse(@Nullable final PNSetUUIDMetadataResult result, @NotNull final PNStatus status) {
9 if (status.isError()) {
10 //handle error
11 }
12 else {
13 //handle result
14 }
15 }
show all 16 lines

Response​

1public class PNSetUUIDMetadataResult extends EntityEnvelope<PNUUIDMetadata> {
2 protected int status;
3 protected PNUUIDMetadata data;
4}
5
6public class PNUUIDMetadata extends PNObject {
7 String id;
8 Object custom;
9 String updated;
10 String eTag;
11 String name;
12 String email;
13 String externalId;
14 String profileUrl;
15}

Remove user metadata​

Removes the metadata from a specified UUID.

Method(s)​

To Remove UUID Metadata you can use the following method(s) in the Android SDK:

1pubnub.removeUUIDMetadata()
2 .uuid(String)
* required
ParameterDescription
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.

Sample code​

1pubnub.removeUUIDMetadata()
2 .async(new PNCallback<PNRemoveUUIDMetadataResult>() {
3 @Override
4 public void onResponse(@Nullable final PNRemoveUUIDMetadataResult result, @NotNull final PNStatus status) {
5 if (status.isError()) {
6 //handle error
7 }
8 else {
9 //handle result
10 }
11 }
12 });

Response​

1public class PNRemoveUUIDMetadataResult extends EntityEnvelope<JsonElement> {
2 int status;
3 JsonElement data;
4}

Channel​

Get metadata for all channels​

Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

To Get All Channel Metadata you can use the following method(s) in the Android SDK:

1pubnub.getAllChannelsMetadata()
2 .limit(Integer)
3 .page(PNPage)
4 .filter(String)
5 .sort(PNSortKey)
6 .includeTotalCount(Boolean)
7 .includeCustom(Boolean)
* required
ParameterDescription
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
listOf()
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.

Sample code​

1pubnub.getAllChannelsMetadata()
2 .async(new PNCallback<PNGetAllChannelsMetadataResult>() {
3 @Override
4 public void onResponse(@Nullable final PNGetAllChannelsMetadataResult result, @NotNull final PNStatus status) {
5 if (status.isError()) {
6 //handle error
7 } else {
8 //handle result
9 }
10 }
11 })

Response​

1public class PNGetAllChannelsMetadataResult extends EntityArrayEnvelope<PNChannelMetadata> {
2 int status;
3 List<PNChannelMetadata> data;
4 Integer totalCount;
5 String next;
6 String prev;
7}
8
9public class PNChannelMetadata extends PNObject {
10 String id;
11 Object custom;
12 String updated;
13 String eTag;
14 String name;
15 String description;
show all 16 lines

Get channel metadata​

Returns metadata for the specified Channel, optionally including the custom data object for each.

Method(s)​

To Get Channel Metadata you can use the following method(s) in the Android SDK:

1pubnub.getChannelMetadata()
2 .channel(String)
3 .includeCustom(Boolean)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.

Sample code​

1pubnub.getChannelMetadata()
2 .channel("myChannel")
3 .async(new PNCallback<PNGetChannelMetadataResult>() {
4 @Override
5 public void onResponse(@Nullable final PNGetChannelMetadataResult result, @NotNull final PNStatus status) {
6 if (status.isError()) {
7 //handle error
8 } else {
9 //handle result
10 }
11 }
12 });

Response​

1public class PNGetChannelMetadataResult extends EntityEnvelope<PNChannelMetadata> {
2 protected int status;
3 protected PNChannelMetadata data;
4}
5
6public class PNChannelMetadata extends PNObject {
7 String id;
8 Object custom;
9 String updated;
10 String eTag;
11 String name;
12 String description;
13}

Set channel metadata​

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a Channel in the database, optionally including the custom data object for each.

Method(s)​

To Set Channel Metadata you can use the following method(s) in the Android SDK:

1pubnub.setChannelMetadata()
2 .channel(String)
3 .name(String)
4 .description(String)
5 .custom(Map<String, Object>)
6 .includeCustom(Boolean)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.
name
Type: String
Default:
n/a
Name for the channel.
description
Type: String
Default:
n/a
Description of a channel.
custom
Type: Map<String, Object>
Default:
n/a
Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn’t supported.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Sample code​

1pubnub.setChannelMetadata()
2 .channel("myChannel")
3 .name("Some Name")
4 .includeCustom(true)
5 .async(new PNCallback<PNSetChannelMetadataResult>() {
6 @Override
7 public void onResponse(@Nullable final PNSetChannelMetadataResult result, @NotNull final PNStatus status) {
8 if (status.isError()) {
9 //handle error
10 } else {
11 //handle result
12 }
13 }
14 });

Response​

1public class PNSetChannelMetadataResult extends EntityEnvelope<PNChannelMetadata> {
2 protected int status;
3 protected PNChannelMetadata data;
4}
5
6public class PNChannelMetadata extends PNObject {
7 String id;
8 Object custom;
9 String updated;
10 String eTag;
11 String name;
12 String description;
13}

Remove channel metadata​

Removes the metadata from a specified channel.

Method(s)​

To Remove Channel Metadata you can use the following method(s) in the Android SDK:

1pubnub.removeChannelMetadata()
2 .channel(String)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.

Sample code​

1pubnub.removeChannelMetadata()
2 .channel("myChannel")
3 .async(new PNCallback<PNRemoveChannelMetadataResult>() {
4 @Override
5 public void onResponse(@Nullable final PNRemoveChannelMetadataResult result, @NotNull final PNStatus status) {
6 if (status.isError()) {
7 //handle error
8 } else {
9 //handle result
10 }
11 }
12 });

Response​

1public class PNRemoveChannelMetadataResult extends EntityEnvelope<JsonElement> {
2 int status;
3 protected JsonElement data;
4}

Channel memberships​

Get channel memberships​

The method returns a list of channel memberships for a user. This method doesn't return subscriptions.

Method(s)​

To Get Memberships you can use the following method(s) in the Android SDK:

1pubnub.getMemberships()
2 .uuid(String)
3 .limit(Integer)
4 .page(PNPage)
5 .filter(String)
6 .sort(List<PNSortKey>)
7 .includeTotalCount(Boolean)
8 .includeCustom(Boolean)
9 .includeChannel(PNChannelDetailsLevel)
* required
ParameterDescription
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.
limit
Type: Integer
Default:
100
The maximum number of objects to retrieve at a time.
page
Type: PNPage
Default:
n/a
The paging object used for pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
listOf()
List of properties to sort by. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
includeTotalCount
Type: Boolean
Default:
false
Request totalCount to be included in paginated response, which is omitted by default.
includeCustom
Type: Boolean
Default:
false
Whether to include custom object in the fetch response.
includeChannel
Type: PNChannelDetailsLevel
Default:
n/a
The level of channel details to return in the membership. Possible values are PNChannelDetailsLevel.CHANNEL which includes basic channel information, and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which also includes the custom object.

Sample code​

1pubnub.getMemberships()
2 .async(new PNCallback<PNGetMembershipsResult>() {
3 @Override
4 public void onResponse(@Nullable final PNGetMembershipsResult result, @NotNull final PNStatus status) {
5 if (status.isError()) {
6 //handle error
7 } else {
8 //handle result
9 }
10 }
11 })

Response​

1public class PNGetMembershipsResult extends EntityArrayEnvelope<PNMembership> {
2 protected Integer totalCount;
3 protected String next;
4 protected String prev;
5 protected int status;
6 protected List<PNMembership> data;
7}
8
9public class PNMembership {
10 PNChannelMetadata channel;
11 Object custom;
12 String updated;
13 String eTag;
14}

Sample code with pagination​

1final PNGetMembershipsResult getMembershipsResult = pubnub.getMemberships()
2 .includeTotalCount(true)
3 .limit(3)
4 .includeCustom(true)
5 .includeChannel("channel_1")
6 .sync();
7if (getMembershipsResult.getNext() != null) {
8 final PNGetMembershipsResult getMembershipsNextPageResult = pubnub.getMemberships()
9 .page(getMembershipsResult.nextPage())
10 .includeTotalCount(true)
11 .limit(3)
12 .includeCustom(true)
13 .includeChannel("channel_1")
14 .sync();
15 System.out.println(getMembershipsNextPageResult);
show all 16 lines

Set channel memberships​

Set channel memberships for a UUID.

Method(s)​

To Set Memberships you can use the following method(s) in the Android SDK:

1pubnub.setMemberships()
2 .channelMemberships(Collection<PNChannelMembership>)
3 .uuid(String)
4 .limit(Integer)
5 .page(PNPage)
6 .filter(String)
7 .sort(PNSort ...)
8 .includeTotalCount(Boolean)
9 .includeCustom(Boolean)
10 .includeChannel(PNChannelDetailLevel)
* required
ParameterDescription
channelMemberships *
Type: List<PNChannelMembership>
Default:
n/a
Collection of PNChannelMembership to add to membership.
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
N/A
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: PNSortKey
Default:
N/A
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeChannel
Type: PNChannelDetailsLevel
Default:
n/a
The level of channel details to return in the membership. Possible values are PNChannelDetailsLevel.CHANNEL which includes basic channel information, and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which also includes the custom object.
API limits

To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.

Sample code​

1pubnub.setMemberships()
2 .channelMemberships(Collections.singletonList(PNChannelMembership.channel("channelId")))
3 .async(new PNCallback<PNSetMembershipResult>() {
4 @Override
5 public void onResponse(@Nullable final PNSetMembershipResult result, @NotNull final PNStatus status) {
6 if (status.isError()) {
7 //handle error
8 } else {
9 //handle result
10 }
11 }
12 });

Response​

1public class PNSetMembershipResult extends EntityArrayEnvelope<PNMembership> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembership> data;
7}
8
9public class PNMembership {
10 PNChannelMetadata channel;
11 Object custom;
12 String updated;
13 String eTag;
14}

Remove channel memberships​

Remove channel memberships for a UUID.

Method(s)​

To Remove Memberships you can use the following method(s) in the Android SDK:

1pubnub.removeMemberships()
2 .channelMemberships(Collection<PNChannelMembership>)
3 .uuid(String)
4 .limit(Integer)
5 .page(PNPage)
6 .filter(String)
7 .sort(PNSort ...)
8 .includeTotalCount(Boolean)
9 .includeCustom(Boolean)
10 .includeChannel(PNChannelDetailLevel)
* required
ParameterDescription
channelMemberships *
Type: List<PNChannelMembership>
Default:
n/a
Collection of PNChannelMembership to add to membership.
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: PNSortKey
Default:
listOf()
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeChannel
Type: PNChannelDetailsLevel
Default:
n/a
The level of channel details to return in the membership. Possible values are PNChannelDetailsLevel.CHANNEL which includes basic channel information, and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which also includes the custom object.

Sample code​

1pubnub.removeMemberships()
2 .channelMemberships(Collections.singletonList(PNChannelMembership.channel("channelId")))
3 .async(new PNCallback<PNRemoveMembershipResult>() {
4 @Override
5 public void onResponse(@Nullable final PNRemoveMembershipResult result, @NotNull final PNStatus status) {
6 if (status.isError()) {
7 //handle error
8 } else {
9 //handle result
10 }
11 }
12 });

Response​

1public class PNRemoveMembershipResults extends EntityArrayEnvelope<PNMembership> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembership> data;
7}
8
9public class PNMembership {
10 PNChannelMetadata channel;
11 Object custom;
12 String updated;
13 String eTag;
14}

Manage channel memberships​

Manage a user's channel memberships.

Method(s)​

To Manage Memberships you can use the following method(s) in the Android SDK:

1pubnub.manageMemberships()
2 .uuid(String)
3 .set(Collection<PNChannelMembership>)
4 .remove(Collection<PNChannelMembership>)
5 .limit(Integer)
6 .page(PNPage)
7 .filter(String)
8 .sort(List<PNSortKey>)
9 .includeTotalCount(Boolean)
10 .includeCustom(Boolean)
11 .includeChannel(PNChannelDetailsLevel)
* required
ParameterDescription
uuid
Type: String
Default:
pubnub.configuration.uuid
Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used.
set *
Type: Collection<PNChannelMembership>
Default:
n/a
List of members PNChannelMembership to add to channel.
remove *
Type: Collection<PNChannelMembership>
Default:
n/a
List of members PNChannelMembership to remove from channel.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
N/A
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeChannel
Type: PNChannelDetailsLevel
Default:
n/a
The level of UUID details to return. Possible values are PNChannelDetailsLevel.CHANNEL which includes basic UUID information, and PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM which also includes the custom object.

Sample code​

1pubnub.manageMemberships()
2 .set(Collections.singletonList(PNChannelMembership.channel("channelIdToSet")))
3 .remove(Collections.singletonList(PNChannelMembership.channel("channelIdToRemove")))
4 .async(new PNCallback<PNManageMembershipResult>() {
5 @Override
6 public void onResponse(@Nullable final PNManageMembershipResult result, @NotNull final PNStatus status) {
7 if (status.isError()) {
8 //handle error
9 } else {
10 //handle result
11 }
12 }
13 });

Response​

1public class PNManageMembershipResult extends EntityArrayEnvelope<PNMembership> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembership> data;
7}
8
9public class PNMembership {
10 PNChannelMetadata channel;
11 Object custom;
12 String updated;
13 String eTag;
14}

Channel members​

Get channel members​

The method returns a list of members in a channel. The list includes user metadata for members that have additional metadata stored in the database.

Method(s)​

To Get Channel Members you can use the following method(s) in the Android SDK:

1pubnub.getChannelMembers()
2 .channel(String)
3 .limit(Integer)
4 .page(PNPage)
5 .filter(String)
6 .sort(List<PNSortKey>)
7 .includeTotalCount(Boolean)
8 .includeCustom(Boolean)
9 .includeUUID(PNUUIDDetailsLevel)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
listOf()
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeUUID
Type: PNUUIDDetailsLevel
Default:
n/a
The level of UUID details to return. Possible values are PNUUIDDetailsLevel.UUID which includes basic UUID information, and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which also includes the custom object.

Sample code​

1pubnub.getChannelMembers()
2 .channel("channelId")
3 .async(new PNCallback<PNGetChannelMembersResult>() {
4 @Override
5 public void onResponse(@Nullable final PNGetChannelMembersResult result, @NotNull final PNStatus status) {
6 if (status.isError()) {
7 //handle error
8 } else {
9 //handle response
10 }
11 }
12 });

Response​

1public class PNRemoveMembershipResults extends EntityArrayEnvelope<PNMembers> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembers> data;
7}
8
9public class PNMembers {
10 PNUUIDMetadata uuid;
11 Object custom;
12 String updated;
13 String eTag;
14}

Set channel members​

This method sets members in a channel.

Method(s)​

To Set Channel Members you can use the following method(s) in the Android SDK:

1pubnub.setChannelMembers()
2 .channel(String)
3 .uuids(Collection<PNUUID>)
4 .limit(Integer)
5 .page(PNPage)
6 .filter(String)
7 .sort(List<PNSortKey>)
8 .includeTotalCount(Boolean)
9 .includeCustom(Boolean)
10 .includeUUID(PNUUIDDetailsLevel)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.
uuids *
Type: Collection<PNUUID>
Default:
n/a
List of members PNUUID to add to channel.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
N/A
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeUUID
Type: PNUUIDDetailsLevel
Default:
n/a
The level of UUID details to return. Possible values are PNUUIDDetailsLevel.UUID which includes basic UUID information, and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which also includes the custom object.
API limits

To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.

Sample code​

1pubnub.setChannelMembers()
2 .channel("channelId")
3 .uuids(Collections.singletonList(PNUUID.uuid("uuid")))
4 .async(new PNCallback<PNSetChannelMembersResult>() {
5 @Override
6 public void onResponse(@Nullable final PNSetChannelMembersResult result, @NotNull final PNStatus status) {
7 if (status.isError()) {
8 //handle error
9 } else {
10 //handle result
11 }
12 }
13 });

Response​

1public class PNSetChannelMembersResult extends EntityArrayEnvelope<PNMembers> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembers> data;
7}
8
9public class PNMembers {
10 PNUUIDMetadata uuid;
11 Object custom;
12 String updated;
13 String eTag;
14}

Remove channel members​

Remove members from a Channel.

Method(s)​

To Remove Channel Members you can use the following method(s) in the Android SDK:

1pubnub.removeChannelMembers()
2 .channel(String)
3 .uuids(Collection<PNUUID>)
4 .limit(Integer)
5 .page(PNPage)
6 .filter(String)
7 .sort(List<PNSortKey>)
8 .includeTotalCount(Boolean)
9 .includeCustom(Boolean)
10 .includeUUID(PNUUIDDetailsLevel)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.
uuids *
Type: Collection<PNUUID>
Default:
n/a
List of members PNUUID to remove from channel.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
N/A
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeUUID
Type: PNUUIDDetailsLevel
Default:
n/a
The level of UUID details to return. Possible values are PNUUIDDetailsLevel.UUID which includes basic UUID information, and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which also includes the custom object.

Sample code​

1pubnub.removeChannelMembers()
2 .channel("channelId")
3 .uuids(Collections.singletonList(PNUUID.uuid("uuid")))
4 .async(new PNCallback<PNRemoveChannelMembersResult>() {
5 @Override
6 public void onResponse(@Nullable final PNRemoveChannelMembersResult result, @NotNull final PNStatus status) {
7 if (status.isError()) {
8 //handle error
9 } else {
10 //handle result
11 }
12 }
13 });

Response​

1public class PNRemoveChannelMembersResult extends EntityArrayEnvelope<PNMembers> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembers> data;
7}
8
9public class PNMembers {
10 PNUUIDMetadata uuid;
11 Object custom;
12 String updated;
13 String eTag;
14}

Manage channel members​

The method Set and Remove channel memberships for a user.

Method(s)​

To Manage Channel Members you can use the following method(s) in the Android SDK:

1pubnub.manageChannelMembers()
2 .channel(String)
3 .set(Collection<PNUUID>)
4 .remove(Collection<PNUUID>)
5 .limit(Integer)
6 .page(PNPage)
7 .filter(String)
8 .sort(List<PNSortKey>)
9 .includeTotalCount(Boolean)
10 .includeCustom(Boolean)
11 .includeUUID(PNUUIDDetailsLevel)
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Channel name.
set *
Type: Collection<PNUUID>
Default:
n/a
List of members PNUUID to add to channel.
remove *
Type: Collection<PNUUID>
Default:
n/a
List of members PNUUID to remove from channel.
limit
Type: Integer
Default:
100
Number of objects to return. Default/Max: 100.
page
Type: PNPage
Default:
n/a
Cursor-based pagination.
filter
Type: String
Default:
n/a
Filter expression. Only matching objects are returned. See filtering.
sort
Type: List<PNSortKey>
Default:
N/A
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
includeTotalCount
Type: Boolean
Default:
false
Whether to include the total count in the paginated response. Default is false.
includeCustom
Type: Boolean
Default:
false
Whether to include the Custom object in the response.
includeUUID
Type: PNUUIDDetailsLevel
Default:
n/a
The level of UUID details to return. Possible values are PNUUIDDetailsLevel.UUID which includes basic UUID information, and PNUUIDDetailsLevel.UUID_WITH_CUSTOM which also includes the custom object.

Sample code​

1pubnub.manageChannelMembers()
2 .channel("channelId")
3 .set(Collections.singletonList(PNUUID.uuid("uuidToSet")))
4 .remove(Collections.singletonList(PNUUID.uuid("uuidToRemove")))
5 .async(new PNCallback<PNManageChannelMembersResult>() {
6 @Override
7 public void onResponse(@Nullable final PNManageChannelMembersResult result, @NotNull final PNStatus status) {
8 if (status.isError()) {
9 //handle error
10 } else {
11 //handle result
12 }
13 }
14 });

Response​

1public class PNManageChannelMembersResult extends EntityArrayEnvelope<PNMembers> {
2 Integer totalCount;
3 String next;
4 String prev;
5 int status;
6 List<PNMembers> data;
7}
8
9public class PNMembers {
10 PNUUIDMetadata uuid;
11 Object custom;
12 String updated;
13 String eTag;
14}

PNChannelMembership class​

PNChannelMembership is a utility class that exposes two factory methods: channel(String channelId) constructs a channel membership, and channelWithCustom(String channelId, Map<String, Object> custom) constructs a channel membership with additional custom metadata.

1public abstract class PNChannelMembership {
2 public static class ChannelId {
3 private String id;
4 }
5
6 private final ChannelId channel;
7
8 public static PNChannelMembership channel(final String channelId) {
9 return new JustChannel(new ChannelId(channelId));
10 }
11
12 public static PNChannelMembership channelWithCustom(final String channelId, final Map<String, Object> custom) {
13 return new ChannelWithCustom(new ChannelId(channelId), new HashMap<>(custom));
14 }
15
show all 22 lines

PNUUID class​

PNUUID is a utility class that exposes two factory methods: uuid(String uuid) constructs a UUID, and uuidWithCustom(String channelId, Map<String, Object> custom) constructs a UUID with additional custom metadata.

1public abstract class PNUUID {
2 public static class UUIDId {
3 private String id;
4 }
5
6 private final UUIDId uuid;
7
8 public static PNUUID uuid(final String uuid) {
9 return new JustUUID(new UUIDId(uuid));
10 }
11 public static PNUUID uuidWithCustom(final String uuid, final Map<String, Object> custom) {
12 return new UUIDWithCustom(new UUIDId(uuid), new HashMap<>(custom));
13 }
14
15 public static class JustUUID extends PNUUID {
show all 21 lines

Was this page useful?

Last updated on