---
source_url: https://www.pubnub.com/docs/sdks/android/api-reference/objects
title: App Context API for Android SDK
updated_at: 2026-05-29T11:09:48.454Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# App Context API for Android SDK

:::warning Unsupported docs
PubNub no longer maintains Android SDK docs, but our [Java SDK](https://www.pubnub.com/docs/sdks/java) or [Kotlin SDK](https://www.pubnub.com/docs/sdks/kotlin) 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](https://www.pubnub.com/docs/general/resources/migration-guides/objects-v2-migration).

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.

:::warning 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](https://admin.pubnub.com)
.
:::

#### Method(s)

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

```java
pubnub.getAllUUIDMetadata()
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| limit | Integer | Optional | `100` | Number of objects to return. Default/Max: 100. |
| page | PNPage | Optional |  | Cursor-based pagination. |
| filter | String? | Optional |  | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| sort | List<PNSortKey> | Optional |  | Sort by `id`, `name`, `updated` with `asc`/`desc` for sort direction (for example, `{name: 'asc'}`). |
| includeTotalCount | Boolean | Optional | `false` | Whether to include the total count in the paginated response. Default is false. |
| includeCustom | Boolean | Optional | `false` | Whether to include the Custom object in the response. |

#### Sample code

```java
pubnub.getAllUUIDMetadata()
    .limit(20)
    .sort(SortKey.asc(SortKey.Key.ID), SortKey.desc(SortKey.Key.UPDATED))
    .includeTotalCount(true)
    .includeCustom(true)
    .async(new PNCallback<PNGetAllUUIDMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNGetAllUUIDMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            }
            else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNGetAllUUIDMetadataResult extends EntityArrayEnvelope<PNUUIDMetadata> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNUUIDMetadata> data;
    PNPage nextPage() {
        return PNPage.next(next);
    }
    PNPage previousPage() {
        return PNPage.previous(prev);
    }
}

public class PNUUIDMetadata extends PNObject {
    String id;
    Object custom;
    String updated;
    String eTag;
    String name;
    String email;
    String externalId;
    String profileUrl;
}
```

### 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:

```java
pubnub.getUUIDMetadata()
    .uuid(String)
    .includeCustom(Boolean)
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: StringDefault: `pubnub.configuration.uuid` | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |

#### Sample code

```java
pubnub.getUUIDMetadata().async(new PNCallback<PNGetUUIDMetadataResult>() {
    @Override
    public void onResponse(@Nullable final PNGetUUIDMetadataResult result, @NotNull final PNStatus status) {
        if (status.isError()) {
            //handle error
        }
        else {
            //handle result
        }
    }
});
```

#### Response

```java
public class PNGetUUIDMetadataResult extends EntityEnvelope<PNUUIDMetadata> {
    int status;
    PNUUIDMetadata data;
}

public class PNUUIDMetadata extends PNObject {
    String id;
    Object custom;
    String updated;
    String eTag;
    String name;
    String email;
    String externalId;
    String profileUrl;
}
```

### Set user metadata

:::warning 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:

```java
pubnub.setUUIDMetadata()
    .uuid(String)
    .name(String)
    .externalId(String)
    .profileUrl(String)
    .email(String)
    .custom(Map<String, Object>)
    .includeCustom(true)
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: StringDefault: `pubnub.configuration.uuid` | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
| `name`Type: StringDefault: n/a | Display name for the user. |
| `externalId`Type: StringDefault: n/a | User's identifier in an external system. |
| `profileUrl`Type: StringDefault: n/a | The URL of the user's profile picture. |
| `email`Type: StringDefault: n/a | The user's email address. |
| `custom`Type: AnyDefault: n/a | Custom JSON values. Can be strings, numbers, or booleans. [Filtering](https://www.pubnub.com/docs/general/metadata/filtering) by `Custom` isn’t supported. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |

:::tip API limits
To learn about the maximum length of parameters used to set user metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-user-metadata).
:::

#### Sample code

```java
pubnub.setUUIDMetadata()
    .name("Foo")
    .profileUrl("http://example.com")
    .email("foo@example.com")
    .includeCustom(true)
    .async(new PNCallback<PNSetUUIDMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNSetUUIDMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            }
            else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNSetUUIDMetadataResult extends EntityEnvelope<PNUUIDMetadata> {
    protected int status;
    protected PNUUIDMetadata data;
}

public class PNUUIDMetadata extends PNObject {
    String id;
    Object custom;
    String updated;
    String eTag;
    String name;
    String email;
    String externalId;
    String profileUrl;
}
```

### 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:

```java
pubnub.removeUUIDMetadata()
    .uuid(String)
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: StringDefault: `pubnub.configuration.uuid` | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |

#### Sample code

```java
pubnub.removeUUIDMetadata()
    .async(new PNCallback<PNRemoveUUIDMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNRemoveUUIDMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            }
            else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNRemoveUUIDMetadataResult extends EntityEnvelope<JsonElement> {
    int status;
    JsonElement data;
}
```

## Channel

### Get metadata for all channels

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

:::warning 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](https://admin.pubnub.com)
.
:::

#### Method(s)

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

```java
pubnub.getAllChannelsMetadata()
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(PNSortKey)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
```

| Parameter | Description |
| --- | --- |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: List`<PNSortKey>`Default: `listOf()` | Sort by `id`, `name`, `updated` with `asc`/`desc` for sort direction (for example, `{name: 'asc'}`). |
| `includeTotalCount`Type: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |

#### Sample code

```java
pubnub.getAllChannelsMetadata()
    .async(new PNCallback<PNGetAllChannelsMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNGetAllChannelsMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    })
```

#### Response

```java
public class PNGetAllChannelsMetadataResult extends EntityArrayEnvelope<PNChannelMetadata> {
    int status;
    List<PNChannelMetadata> data;
    Integer totalCount;
    String next;
    String prev;
}

public class PNChannelMetadata extends PNObject {
    String id;
    Object custom;
    String updated;
    String eTag;
    String name;
    String description;
}
```

### 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:

```java
pubnub.getChannelMetadata()
    .channel(String)
    .includeCustom(Boolean)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |

#### Sample code

```java
pubnub.getChannelMetadata()
    .channel("myChannel")
    .async(new PNCallback<PNGetChannelMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNGetChannelMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNGetChannelMetadataResult extends EntityEnvelope<PNChannelMetadata> {
    protected int status;
    protected PNChannelMetadata data;
}

public class PNChannelMetadata extends PNObject {
    String id;
    Object custom;
    String updated;
    String eTag;
    String name;
    String description;
}
```

### Set channel metadata

:::warning 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:

```java
pubnub.setChannelMetadata()
    .channel(String)
    .name(String)
    .description(String)
    .custom(Map<String, Object>)
    .includeCustom(Boolean)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |
| `name`Type: StringDefault: n/a | Name for the channel. |
| `description`Type: StringDefault: n/a | Description of a channel. |
| `custom`Type: Map`<String, Object>`Default: n/a | Custom JSON values. Can be strings, numbers, or booleans. [Filtering](https://www.pubnub.com/docs/general/metadata/filtering) by `Custom` isn’t supported. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Sample code

```java
pubnub.setChannelMetadata()
    .channel("myChannel")
    .name("Some Name")
    .includeCustom(true)
    .async(new PNCallback<PNSetChannelMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNSetChannelMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNSetChannelMetadataResult extends EntityEnvelope<PNChannelMetadata> {
    protected int status;
    protected PNChannelMetadata data;
}

public class PNChannelMetadata extends PNObject {
    String id;
    Object custom;
    String updated;
    String eTag;
    String name;
    String description;
}
```

### 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:

```java
pubnub.removeChannelMetadata()
    .channel(String)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |

#### Sample code

```java
pubnub.removeChannelMetadata()
    .channel("myChannel")
    .async(new PNCallback<PNRemoveChannelMetadataResult>() {
        @Override
        public void onResponse(@Nullable final PNRemoveChannelMetadataResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNRemoveChannelMetadataResult extends EntityEnvelope<JsonElement> {
    int status;
    protected JsonElement data;
}
```

## 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:

```java
pubnub.getMemberships()
    .uuid(String)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeChannel(PNChannelDetailsLevel)
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: StringDefault: `pubnub.configuration.uuid` | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
| `limit`Type: IntegerDefault: `100` | The maximum number of objects to retrieve at a time. |
| `page`Type: PNPageDefault: n/a | The paging object used for pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/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: BooleanDefault: `false` | Request `totalCount` to be included in paginated response, which is omitted by default. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include `custom` object in the fetch response. |
| `includeChannel`Type: PNChannelDetailsLevelDefault: 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

```java
pubnub.getMemberships()
    .async(new PNCallback<PNGetMembershipsResult>() {
        @Override
        public void onResponse(@Nullable final PNGetMembershipsResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    })
```

#### Response

```java
public class PNGetMembershipsResult extends EntityArrayEnvelope<PNMembership> {
    protected Integer totalCount;
    protected String next;
    protected String prev;
    protected int status;
    protected List<PNMembership> data;
}

public class PNMembership {
    PNChannelMetadata channel;
    Object custom;
    String updated;
    String eTag;
}
```

#### Sample code with pagination

```java
final PNGetMembershipsResult getMembershipsResult = pubnub.getMemberships()
    .includeTotalCount(true)
    .limit(3)
    .includeCustom(true)
    .includeChannel("channel_1")
    .sync();
if (getMembershipsResult.getNext() != null) {
    final PNGetMembershipsResult getMembershipsNextPageResult = pubnub.getMemberships()
        .page(getMembershipsResult.nextPage())
        .includeTotalCount(true)
        .limit(3)
        .includeCustom(true)
        .includeChannel("channel_1")
        .sync();
    System.out.println(getMembershipsNextPageResult);
}
```

### 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:

```java
pubnub.setMemberships()
    .channelMemberships(Collection<PNChannelMembership>)
    .uuid(String)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(PNSort ...)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeChannel(PNChannelDetailLevel)
```

| Parameter | Description |
| --- | --- |
| `channelMemberships` *Type: List`<PNChannelMembership>`Default: n/a | Collection of [PNChannelMembership](#pnchannelmembership-class) to add to membership. |
| `uuid`Type: StringDefault: `pubnub.configuration.uuid` | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: N/A | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: PNSortKeyDefault: N/A | Sort by `id`, `name`, `updated` with `asc`/`desc` for sort direction (for example, `{name: 'asc'}`). |
| `includeTotalCount`Type: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeChannel`Type: PNChannelDetailsLevelDefault: 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. |

:::tip API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-membership-metadata).
:::

#### Sample code

```java
pubnub.setMemberships()
    .channelMemberships(Collections.singletonList(PNChannelMembership.channel("channelId")))
    .async(new PNCallback<PNSetMembershipResult>() {
        @Override
        public void onResponse(@Nullable final PNSetMembershipResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNSetMembershipResult extends EntityArrayEnvelope<PNMembership> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembership> data;
}

public class PNMembership {
    PNChannelMetadata channel;
    Object custom;
    String updated;
    String eTag;
}
```

### 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:

```java
pubnub.removeMemberships()
    .channelMemberships(Collection<PNChannelMembership>)
    .uuid(String)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(PNSort ...)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeChannel(PNChannelDetailLevel)
```

| Parameter | Description |
| --- | --- |
| `channelMemberships` *Type: List`<PNChannelMembership>`Default: n/a | Collection of [PNChannelMembership](#pnchannelmembership-class) to add to membership. |
| `uuid`Type: StringDefault: `pubnub.configuration.uuid` | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: PNSortKeyDefault: `listOf()` | Sort by `id`, `name`, `updated` with `asc`/`desc` for sort direction (for example, `{name: 'asc'}`). |
| `includeTotalCount`Type: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeChannel`Type: PNChannelDetailsLevelDefault: 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

```java
pubnub.removeMemberships()
    .channelMemberships(Collections.singletonList(PNChannelMembership.channel("channelId")))
    .async(new PNCallback<PNRemoveMembershipResult>() {
        @Override
        public void onResponse(@Nullable final PNRemoveMembershipResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNRemoveMembershipResults extends EntityArrayEnvelope<PNMembership> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembership> data;
}

public class PNMembership {
    PNChannelMetadata channel;
    Object custom;
    String updated;
    String eTag;
}
```

### 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:

```java
pubnub.manageMemberships()
    .uuid(String)
    .set(Collection<PNChannelMembership>)
    .remove(Collection<PNChannelMembership>)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeChannel(PNChannelDetailsLevel)
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: StringDefault: `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](#pnchannelmembership-class) to add to channel. |
| `remove` *Type: `Collection<PNChannelMembership>`Default: n/a | List of members [PNChannelMembership](#pnchannelmembership-class) to remove from channel. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/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: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeChannel`Type: PNChannelDetailsLevelDefault: 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

```java
pubnub.manageMemberships()
    .set(Collections.singletonList(PNChannelMembership.channel("channelIdToSet")))
    .remove(Collections.singletonList(PNChannelMembership.channel("channelIdToRemove")))
    .async(new PNCallback<PNManageMembershipResult>() {
        @Override
        public void onResponse(@Nullable final PNManageMembershipResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNManageMembershipResult extends EntityArrayEnvelope<PNMembership> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembership> data;
}

public class PNMembership {
    PNChannelMetadata channel;
    Object custom;
    String updated;
    String eTag;
}
```

## 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:

```java
pubnub.getChannelMembers()
    .channel(String)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeUUID(PNUUIDDetailsLevel)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: List`<PNSortKey>`Default: `listOf()` | Sort by `id`, `name`, `updated` with `asc`/`desc` for sort direction (for example, `{name: 'asc'}`). |
| `includeTotalCount`Type: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeUUID`Type: PNUUIDDetailsLevelDefault: 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

```java
pubnub.getChannelMembers()
    .channel("channelId")
    .async(new PNCallback<PNGetChannelMembersResult>() {
        @Override
        public void onResponse(@Nullable final PNGetChannelMembersResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle response
            }
        }
    });
```

#### Response

```java
public class PNRemoveMembershipResults extends EntityArrayEnvelope<PNMembers> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembers> data;
}

public class PNMembers {
    PNUUIDMetadata uuid;
    Object custom;
    String updated;
    String eTag;
}
```

### 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:

```java
pubnub.setChannelMembers()
    .channel(String)
    .uuids(Collection<PNUUID>)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeUUID(PNUUIDDetailsLevel)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |
| `uuids` *Type: Collection`<PNUUID>`Default: n/a | List of members [PNUUID](#pnuuid-class) to add to channel. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/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: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeUUID`Type: PNUUIDDetailsLevelDefault: 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. |

:::tip API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-members-metadata).
:::

#### Sample code

```java
pubnub.setChannelMembers()
    .channel("channelId")
    .uuids(Collections.singletonList(PNUUID.uuid("uuid")))
    .async(new PNCallback<PNSetChannelMembersResult>() {
        @Override
        public void onResponse(@Nullable final PNSetChannelMembersResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNSetChannelMembersResult extends EntityArrayEnvelope<PNMembers> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembers> data;
}

public class PNMembers {
    PNUUIDMetadata uuid;
    Object custom;
    String updated;
    String eTag;
}
```

### 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:

```java
pubnub.removeChannelMembers()
    .channel(String)
    .uuids(Collection<PNUUID>)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeUUID(PNUUIDDetailsLevel)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |
| `uuids` *Type: Collection`<PNUUID>`Default: n/a | List of members [PNUUID](#pnuuid-class) to remove from channel. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/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: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeUUID`Type: PNUUIDDetailsLevelDefault: 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

```java
pubnub.removeChannelMembers()
    .channel("channelId")
    .uuids(Collections.singletonList(PNUUID.uuid("uuid")))
    .async(new PNCallback<PNRemoveChannelMembersResult>() {
        @Override
        public void onResponse(@Nullable final PNRemoveChannelMembersResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNRemoveChannelMembersResult extends EntityArrayEnvelope<PNMembers> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembers> data;
}

public class PNMembers {
    PNUUIDMetadata uuid;
    Object custom;
    String updated;
    String eTag;
}
```

### 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:

```java
pubnub.manageChannelMembers()
    .channel(String)
    .set(Collection<PNUUID>)
    .remove(Collection<PNUUID>)
    .limit(Integer)
    .page(PNPage)
    .filter(String)
    .sort(List<PNSortKey>)
    .includeTotalCount(Boolean)
    .includeCustom(Boolean)
    .includeUUID(PNUUIDDetailsLevel)
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |
| `set` *Type: Collection`<PNUUID>`Default: n/a | List of members [PNUUID](#pnuuid-class) to add to channel. |
| `remove` *Type: Collection`<PNUUID>`Default: n/a | List of members [PNUUID](#pnuuid-class) to remove from channel. |
| `limit`Type: IntegerDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: PNPageDefault: n/a | Cursor-based pagination. |
| `filter`Type: StringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/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: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `includeCustom`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `includeUUID`Type: PNUUIDDetailsLevelDefault: 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

```java
pubnub.manageChannelMembers()
    .channel("channelId")
    .set(Collections.singletonList(PNUUID.uuid("uuidToSet")))
    .remove(Collections.singletonList(PNUUID.uuid("uuidToRemove")))
    .async(new PNCallback<PNManageChannelMembersResult>() {
        @Override
        public void onResponse(@Nullable final PNManageChannelMembersResult result, @NotNull final PNStatus status) {
            if (status.isError()) {
                //handle error
            } else {
                //handle result
            }
        }
    });
```

#### Response

```java
public class PNManageChannelMembersResult extends EntityArrayEnvelope<PNMembers> {
    Integer totalCount;
    String next;
    String prev;
    int status;
    List<PNMembers> data;
}

public class PNMembers {
    PNUUIDMetadata uuid;
    Object custom;
    String updated;
    String eTag;
}
```

## 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.

```java
public abstract class PNChannelMembership {
    public static class ChannelId {
        private String id;
    }

    private final ChannelId channel;

    public static PNChannelMembership channel(final String channelId) {
        return new JustChannel(new ChannelId(channelId));
    }

    public static PNChannelMembership channelWithCustom(final String channelId, final Map<String, Object> custom) {
        return new ChannelWithCustom(new ChannelId(channelId), new HashMap<>(custom));
    }

    public static class JustChannel extends PNChannelMembership {}

    public static class ChannelWithCustom extends PNChannelMembership {
        @JsonAdapter(CustomPayloadJsonInterceptor.class)
        private final Object custom;
    }
}
```

## 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.

```java
public abstract class PNUUID {
    public static class UUIDId {
        private String id;
    }

    private final UUIDId uuid;

    public static PNUUID uuid(final String uuid) {
        return new JustUUID(new UUIDId(uuid));
    }
    public static PNUUID uuidWithCustom(final String uuid, final Map<String, Object> custom) {
        return new UUIDWithCustom(new UUIDId(uuid), new HashMap<>(custom));
    }

    public static class JustUUID extends PNUUID {
    }

    public static class UUIDWithCustom extends PNUUID {
        private final Object custom;
    }
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **Channel pattern** - A way to group and analyze channel data to track performance metrics like message counts and user engagement over time with PubNub Insights.
* **User** - An individual or entity that interacts with a system, application, or service. In PubNub, a user typically refers to someone who sends or receives messages through the platform, identified by a unique user ID or username.
* **User ID** - UTF-8 encoded, unique string of up to 92 characters used to identify a single client (end user, device, or server) that connects to PubNub.
