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.delete() to remove a tag.
- Kotlin
- Java
// Get the tag first, then call delete()
Tag.getTags { tags, error ->
if (error == null && tags != null) {
val tag = tags.find { it.tagId == "my_tag_id" }
tag?.delete { deleteError ->
if (deleteError == null) {
// Tag deleted
}
}
}
}
Tag.getTags((tags, error) -> {
if (error == null && tags != null) {
for (Tag tag : tags) {
if ("my_tag_id".equals(tag.getTagId())) {
tag.delete(deleteError -> {
if (deleteError == null) {
// Tag deleted
}
});
break;
}
}
}
});
Update a tag
Use tag.update() to update a tag's name.
- Kotlin
- Java
tag.update("New Name") { error ->
if (error == null) {
// Tag updated
}
}
tag.update("New Name", error -> {
if (error == null) {
// Tag updated
}
});
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 ->
println("Tag: ${tag.tagId}, Name: ${tag.tagName}")
}
}
}
Tag.getTags((tags, error) -> {
if (error == null && tags != null) {
for (Tag tag : tags) {
System.out.println("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.
NCEngine.addTagHandler("TAG_SYNC", object : TagHandler {
override fun onTagChanged() {
// Tag definitions changed on another device, refresh
Tag.getTags { tags, error ->
if (error == null && tags != null) {
// Update UI with latest tags
}
}
}
override fun onChannelTagChanged() {
// Channel-tag associations changed on another device, refresh
Tag.getTags { tags, error ->
if (error == null && tags != null) {
// Update UI with latest channel-tag data
}
}
}
})