Managing channel tag data
Create and manage channel tag data using the Nexconn SDK. The SDK lets users create Tag objects for organizing channels into groups. Each user can create up to 20 tags. Tag data created on the client syncs with the server.
Tag properties:
| Parameter | Type | Description |
|---|---|---|
tagId | String | Unique tag identifier. |
tagName | String | Tag name (max 15 characters). Duplicate names are allowed. |
count | int | Number of matching channels. |
This page covers tag data management only. For adding tags to channels and retrieving channels by tag, see Tagging Channels.
Create a tag
Use Tag.createTag() with CreateTagParams to create a tag. Each user can create up to 20 tags.
- Kotlin
- Java
val params = CreateTagParams(
tagId = "my_tag_id",
tagName = "Favorites"
)
Tag.createTag(params) { tag, error ->
if (error == null && tag != null) {
// Tag created successfully
} else {
// Failed
}
}
CreateTagParams params = new CreateTagParams("my_tag_id", "Favorites");
Tag.createTag(params, (tag, error) -> {
if (error == null && tag != null) {
// Tag created successfully
} else {
// Failed
}
});
Remove a tag
Use Tag.getTag() to retrieve the tag instance, then call tag.delete() to remove it.
- Kotlin
- Java
Tag.getTag("my_tag_id") { tag, error ->
if (error == null && tag != null) {
tag.delete { deleteError ->
if (deleteError == null) {
Log.d("Tag", "Tag deleted")
} else {
Log.e("Tag", "Delete failed: ${deleteError.message}")
}
}
}
}
Tag.getTag("my_tag_id", (tag, error) -> {
if (error == null && tag != null) {
tag.delete(deleteError -> {
if (deleteError == null) {
Log.d("Tag", "Tag deleted");
} else {
Log.e("Tag", "Delete failed: " + deleteError.getMessage());
}
});
}
});
Update a tag
Use Tag.getTag() to retrieve the tag instance, then call tag.update() to update its name.
- Kotlin
- Java
Tag.getTag("my_tag_id") { tag, error ->
if (error == null && tag != null) {
tag.update("New Name") { updateError ->
if (updateError == null) {
Log.d("Tag", "Tag updated")
} else {
Log.e("Tag", "Update failed: ${updateError.message}")
}
}
}
}
Tag.getTag("my_tag_id", (tag, error) -> {
if (error == null && tag != null) {
tag.update("New Name", updateError -> {
if (updateError == null) {
Log.d("Tag", "Tag updated");
} else {
Log.e("Tag", "Update failed: " + updateError.getMessage());
}
});
}
});
Get tag list
Use Tag.getTags() to retrieve all tags created by the current user.
- Kotlin
- Java
Tag.getTags { tags, error ->
if (error == null && tags != null) {
tags.forEach { tag ->
Log.d("Tag", "Tag: ${tag.tagId}, Name: ${tag.tagName}")
}
}
}
Tag.getTags((tags, error) -> {
if (error == null && tags != null) {
for (Tag tag : tags) {
Log.d("Tag", "Tag: " + tag.getTagId() + ", Name: " + tag.getTagName());
}
}
});
Multi-device tag sync
The SDK supports multi-device login for the same user account. Use NCEngine.addTagHandler() to receive notifications when tags are modified on another device. After receiving a notification, call Tag.getTags() to fetch the latest tag data from the server.
- Modifying tags on the current device does not trigger this callback. The server only notifies the SDK on other devices logged in with the same account.
- Kotlin
- Java
NCEngine.addTagHandler("TAG_SYNC", object : TagHandler {
override fun onTagChanged(event: TagChangedEvent) {
// Tag definitions changed on another device, refresh
Tag.getTags { tags, error ->
if (error == null && tags != null) {
// Update UI with latest tags
}
}
}
override fun onChannelTagChanged(event: ChannelTagChangedEvent) {
// Channel-tag associations changed on another device, refresh
Tag.getTags { tags, error ->
if (error == null && tags != null) {
// Update UI with latest channel-tag data
}
}
}
})
NCEngine.addTagHandler("TAG_SYNC", new TagHandler() {
@Override
public void onTagChanged(@NonNull TagChangedEvent event) {
// Tag definitions changed on another device, refresh
Tag.getTags((tags, error) -> {
if (error == null && tags != null) {
// Update UI with latest tags
}
});
}
@Override
public void onChannelTagChanged(@NonNull ChannelTagChangedEvent event) {
// Channel-tag associations changed on another device, refresh
Tag.getTags((tags, error) -> {
if (error == null && tags != null) {
// Update UI with latest channel-tag data
}
});
}
});