# \*Incoming tags managing

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:

```kotlin
    /**
	 * 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()
```

## TagsProcessingListener

It has inside 4 methods:

1. `onTagAdd(tag: Tag, activationTime: Long, status: Status)` - callback of the `addFutureTrackTag` 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 server\
   `Status.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 earlier\
   `Status.ERROR_WRONG_TIME` when user sent wrong tme (future)\
   `Status.ERROR_INVALID_TAG_SPECIFIED` when tag name is null or empty<br>
2. `onTagRemove(tag: Tag, deactivationTime: Long, status: Status)` - callback of the `removeFutureTrackTag` 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 server\
   `Status.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 exist\
   `Status.ERROR_WRONG_TIME` when user sent wrong tme (future)\
   `Status.ERROR_INVALID_TAG_SPECIFIED` when tag name is null or empty<br>
3. `onAllTagsRemove(deactivatedTagsCount: Int, time: Long, status: Status)`- callback of the `removeAllFutureTrackTags` 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 proceeded\
   `Status.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\
   `Status.ERROR_WRONG_TIME` when user sent wrong tme (future)<br>
4. `onGetTags(tags: Array<Tag>?, time: Long, status: Status)`- callback of the `getFutureTrackTags` method\
   Parameters:\
   1\. `tags` - `Array<Tag>?` - array of tags. Can be null if status in not `SUCCESS`\
   2\. `time` - UNIX-timestamp in milliseconds (time of the operation)\
   3.`status` - Status of the operation. Status can be:\
   `Status.SUCCESS` - success\
   `Status.OFFLINE` if there is no internet connection

**Sample of using** TagsProcessingListener

1. Implement it on your side

```kotlin
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:

```kotlin
TrackingApi.getInstance().addTagsProcessingCallback(listener)
```

3\. Don’t forget to remove listener when it’s not needed:

```kotlin
TrackingApi.getInstance().removeTagsProcessingCallback()
```

## Tags processing receiver

`TagsProcessingReceiver` works the same as `TagsProcessingListener` . But it's a `BroadcastReceiver`.

Methods are the same at all.

**Sample of using** `TagsProcessingReceiver`&#x20;

1. Add the following class to your application

```kotlin
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.

```markup
<receiver android:name=".TagsReceiver"/>
```

3\. Register it with SDK:

```kotlin
TrackingApi.getInstance().registerTagsReceiver(TagsReceiver::class.java)
```

4\. Don't forget to unregister when it’s not needed:

```kotlin
TrackingApi.getInstance().unregisterTagsReceiver()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-old.telematicssdk.com/sdk-installation/android-sdk-installation/incoming-tags-managing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
