*Incoming tags managing
Available since v2.2.243
In 2.2.243 version of the SDK incoming tags processing was added. It supports both online and offline modes. All tags will be uploaded with the specified time when they were made.
Methods doesn’t return any data. You can register a
TagsProcessingListener
or TagsProcessingReceiver
(it is a BroadcastReceiver you have to implement on your side and register with the SDK) for subscribing to tags processing updates.Methods for managing:
/**
* Get tags
*
* The result of the operation you can get through the registration of [TagsProcessingListener] or [TagsProcessingReceiver].
* Check [registerTagsReceiver] and [addTagsProcessingCallback]
*
* @throws IllegalStateException if [initialize] never called. See also [isInitialized].
*/
fun getFutureTrackTags()
/**
* Create new tag
*
* The result of the operation you can get through the registration of [TagsProcessingListener] or [TagsProcessingReceiver].
* Check [registerTagsReceiver] and [addTagsProcessingCallback]
* @param tag tag's name
* @param source source of the tag. Optional parameter
*
* @throws IllegalStateException if [initialize] never called. See also [isInitialized].
*/
fun addFutureTrackTag(tag: String?, source: String? = null)
/**
* Remove specified tag
*
* The result of the operation you can get through the registration of [TagsProcessingListener] or [TagsProcessingReceiver].
* Check [registerTagsReceiver] and [addTagsProcessingCallback]
* @param tag tag's name
*
* @throws IllegalStateException if [initialize] never called. See also [isInitialized].
*/
fun removeFutureTrackTag(tag: String?)
/**
* Remove all tags.
*
* The result of the operation you can get through the registration of [TagsProcessingListener] or [TagsProcessingReceiver].
* Check [registerTagsReceiver] and [addTagsProcessingCallback]
*
* @throws IllegalStateException if [initialize] was never called. See also [isInitialized].
*/
fun removeAllFutureTrackTags()
It has inside 4 methods:
- 1.
onTagAdd(tag: Tag, activationTime: Long, status: Status)
- callback of theaddFutureTrackTag
method Parameters: 1.tag
- Tag instance for adding 2.activationTime
- UNIX-timestamp in milliseconds of the tag activation time 3.status
- Status of the operation. Status can be:Status.SUCCESS
when tag was successfully uploaded to serverStatus.OFFLINE
when tag wasn’t uploaded to server (no internet, etc.), but will be sent later (when internet connection will appears)Status.ERROR_TAG_OPERATION
when operation can’t be proceeded on server because tag was already created earlierStatus.ERROR_WRONG_TIME
when user sent wrong tme (future)Status.ERROR_INVALID_TAG_SPECIFIED
when tag name is null or empty - 2.
onTagRemove(tag: Tag, deactivationTime: Long, status: Status)
- callback of theremoveFutureTrackTag
method Parameters: 1.tag
- Tag instance for removing 2.deactivationTime
- UNIX-timestamp in milliseconds of the tag deactivation time 3.status
- Status of the operation. Status can be:Status.SUCCESS
when tag was successfully removed from serverStatus.OFFLINE
when operation wasn’t pushed to server (no internet, etc.), but will be sent later (when internet connection will appears)Status.ERROR_TAG_OPERATION
when operation can’t be proceeded on server because tag wasn’t existStatus.ERROR_WRONG_TIME
when user sent wrong tme (future)Status.ERROR_INVALID_TAG_SPECIFIED
when tag name is null or empty - 3.
onAllTagsRemove(deactivatedTagsCount: Int, time: Long, status: Status)
- callback of theremoveAllFutureTrackTags
method Parameters: 1.deactivatedTagsCount
- deactivated tags amount 2.time
- UNIX-timestamp in milliseconds (time of the operation) 3.status
- Status of the operation. Status can be:Status.SUCCESS
"Remove all tags" request was successfully proceededStatus.OFFLINE
when operation wasn’t pushed to server (no internet, etc.), but will be sent later (when internet connection will appears)Status.ERROR_TAG_OPERATION
when operation can’t be proceeded on serverStatus.ERROR_WRONG_TIME
when user sent wrong tme (future) - 4.
onGetTags(tags: Array<Tag>?, time: Long, status: Status)
- callback of thegetFutureTrackTags
method Parameters: 1.tags
-Array<Tag>?
- array of tags. Can be null if status in notSUCCESS
2.time
- UNIX-timestamp in milliseconds (time of the operation) 3.status
- Status of the operation. Status can be:Status.SUCCESS
- successStatus.OFFLINE
if there is no internet connection
Sample of using TagsProcessingListener
- 1.Implement it on your side
val listener = object : TagsProcessingListener {
override fun onTagAdd(status: Status, tag: Tag, activationTime: Long) {
runOnUiThread {
when (status) {
Status.SUCCESS -> {
// tag successfully added
}
Status.OFFLINE -> {
// tag was saved to the local storage. It will be sent later when internet will be available
}
Status.ERROR_TAG_OPERATION -> {
// unable to add tag to server (The tag has already been created)
}
Status.ERROR_WRONG_TIME -> {
// Unable to perform operation. Future time specified.
}
Status.ERROR_INVALID_TAG_SPECIFIED -> {
// null or blank tag name specified
}
}
}
}
override fun onTagRemove(status: Status, tag: Tag, deactivationTime: Long) {
runOnUiThread {
when (status) {
Status.SUCCESS -> {
// tag was successfully removed
}
Status.OFFLINE -> {
// tag deactivation was saved to the local storage. It will be sent later when internet will be available
}
Status.ERROR_TAG_OPERATION -> {
// unable to add tag to server (Tag doesn't exist. Unable to remove)
}
Status.ERROR_WRONG_TIME -> {
// Unable to perform operation. Future time specified.
}
Status.ERROR_INVALID_TAG_SPECIFIED -> {
// null or blank tag name specified
}
}
}
}
override fun onAllTagsRemove(status: Status, deactivatedTagsCount: Int, time: Long) {
runOnUiThread {
when (status) {
Status.SUCCESS -> {
// "Remove all tags" request was successfully proceeded
}
Status.OFFLINE -> {
// "Remove all tags" request was saved to the local storage. It will be sent later when internet will be available
}
Status.ERROR_TAG_OPERATION -> {
// unable to proceed on server
}
Status.ERROR_WRONG_TIME -> {
// Unable to perform operation. Future time specified.
}
}
}
}
override fun onGetTags(status: Status, tags: Array<Tag>?, time: Long) {
runOnUiThread {
when (status) {
Status.SUCCESS -> {
// all cached requests (for add/ remove/ remove all tags) were proceeded and tags fetched successfully
}
Status.OFFLINE {
// can't fetch tags list. Try again later
}
}
}
}
}
2. Add it to the SDK:
TrackingApi.getInstance().addTagsProcessingCallback(listener)
3. Don’t forget to remove listener when it’s not needed:
TrackingApi.getInstance().removeTagsProcessingCallback()
TagsProcessingReceiver
works the same as TagsProcessingListener
. But it's a BroadcastReceiver
.Methods are the same at all.
Sample of using
TagsProcessingReceiver
- 1.Add the following class to your application
class TagsReceiver : TagsProcessingReceiver() {
override fun onTagAdd(status: Status, tag: Tag, activationTime: Long) {
when (status) {
Status.SUCCESS -> {
// tag successfully added
}
Status.OFFLINE -> {
// tag was saved to the local storage. It will be sent later when internet will be available
}
Status.ERROR_TAG_OPERATION -> {
// unable to add tag to server (The tag has already been created)
}
Status.ERROR_WRONG_TIME -> {
// Unable to perform operation. Future time specified.
}
Status.ERROR_INVALID_TAG_SPECIFIED -> {
// null or blank tag name specified
}
}
}
override fun onTagRemove(status: Status, tag: Tag, deactivationTime: Long) {
when (status) {
Status.SUCCESS -> {
// tag was successfully removed
}
Status.OFFLINE -> {
// tag deactivation was saved to the local storage. It will be sent later when internet will be available
}
Status.ERROR_TAG_OPERATION -> {
// unable to add tag to server (Tag doesn't exist. Unable to remove)
}
Status.ERROR_WRONG_TIME -> {
// Unable to perform operation. Future time specified.
}
Status.ERROR_INVALID_TAG_SPECIFIED -> {
// null or blank tag name specified
}
}
}
override fun onAllTagsRemove(status: Status, deactivatedTagsCount: Int, time: Long) {
when (status) {
Status.SUCCESS -> {
// "Remove all tags" request was successfully proceeded
}
Status.OFFLINE -> {
// "Remove all tags" request was saved to the local storage. It will be sent later when internet will be available
}
Status.ERROR_TAG_OPERATION -> {
// unable to proceed on server
}
Status.ERROR_WRONG_TIME -> {
// Unable to perform operation. Future time specified.
}
}
}
override fun onGetTags(status: Status, tags: Array<Tag>?, time: Long) {
when(status) {
Status.SUCCESS -> {
// all cached requests (for add/ remove/ remove all tags) were proceeded and tags fetched successfully
}
Status.OFFLINE -> {
// can't fetch tags list. Try again later
}
}
}
}
2. Add this broadcast receiver to the manifest before the
</application>
tag.<receiver android:name=".TagsReceiver"/>
3. Register it with SDK:
TrackingApi.getInstance().registerTagsReceiver(TagsReceiver::class.java)
4. Don't forget to unregister when it’s not needed:
TrackingApi.getInstance().unregisterTagsReceiver()
Last modified 2yr ago