App Context API for PubNub Android SDK
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 easily 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 set or removed from the database. 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.
Method(s)
To Get All UUID Metadata
you can use the following method(s) in the Android SDK:
pubnub.getAllUUIDMetadata()
.limit(Integer)
.page(PNPage)
.filter(String)
.sort(List<PNSortKey>)
.includeTotalCount(Boolean)
.includeCustom(Boolean)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
limit | Integer | Optional | 100 | The maximum number of objects to retrieve at a time. |
page | PNPage | Optional | The paging object used for pagination. | |
filter | String? | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here | |
sort | List<PNSortKey> | Optional | 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 | Boolean | Optional | false | Request totalCount to be included in paginated response, which is omitted by default. |
includeCustom | Boolean | Optional | false | Whether to include the custom object in the fetch response. |
Basic Usage
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
}
}
show all 16 linesResponse
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 {
show all 24 linesGet 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:
pubnub.getUUIDMetadata()
.uuid(String)
.includeCustom(Boolean)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
includeCustom | Boolean | Optional | false | Whether to include the custom object in the fetch response. |
Basic Usage
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
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
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:
pubnub.setUUIDMetadata()
.uuid(String)
.name(String)
.externalId(String)
.profileUrl(String)
.email(String)
.custom(Map<String, Object>)
.includeCustom(true)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
name | String | Optional | Display name for the user. | |
externalId | String | Optional | User's identifier in an external system. | |
profileUrl | String | Optional | The URL of the user's profile picture. | |
email | String | Optional | The user's email address. | |
custom | Any | Optional | Any object of key-value pairs with supported data types. App Context filtering language doesn’t support filtering by custom properties. | |
includeCustom | Boolean | Optional | false | Whether to include the custom object in the fetch response. |
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Basic Usage
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
}
}
show all 16 linesResponse
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:
pubnub.removeUUIDMetadata()
.uuid(String)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
uuid | String | Optional | pubnub.configuration.uuid | Unique UUID Metadata identifier. If not supplied, then UUID from configuration will be used. |
Basic Usage
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
public class PNRemoveUUIDMetadataResult extends EntityEnvelope<JsonElement> {
int status;
JsonElement data;
}