# ActiveFence Video Content Moderation (/en/realtime-media/marketplace/build/add-moderation-and-intelligence/activefence/android)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

[ActiveFence](https://www.activefence.com/) provides trust and safety solutions to protect online platforms and their users from malicious behavior and content. By integrating ActiveFence capabilities in your app, you can design the exact content moderation solution you need. Content moderation is powered by AI-driven automated detection for text, audio, image, and video content, enabling you to moderate, enforce policies, manage user flags, and send notifications across multiple abuse areas and languages.

      
    The following figure shows the ActiveFence workflow to moderate content sent by a specific user to a channel:

    ![ActiveFence workflow](https://assets-docs.agora.io/images/extensions-marketplace/active-fence.svg)

    This page shows you how to integrate and use the ActiveFence content detection and moderation extension in your app.

    ## Prerequisites [#prerequisites]

    The development environment requirements are as follows:

    * Android Studio 4.1 or later.
    * A physical device (not an emulator) running Android 5.0 or later.
    * Implemented the [SDK quickstart](../../../video/quickstart.mdx).
    * If you use RTC SDK tokens, ensure that you are using AccessToken2 to enable ActiveFence video content moderation.

    ## Project setup [#project-setup]

    In order to configure ActiveFence:

    1. Set up your ActiveFence account.
       * In Agora Extensions Marketplace, select ActiveFence, then click **Activate Your Account**; or contact `extensions.marketplace@agora.io` to activate the extension.
       * Follow the activation email instructions to activate your ActiveFence account.
    2. Configure your ActiveFence API key.
       * In ActiveFence, open **Account Settings**.
       * Click **Data Management** > **ActiveFence API Keys** and create a key.
       * Save the key securely and share the key information with Agora so the services can be connected.
    3. Connect your app to your ActiveFence account.
       * Email `support@agora.io` and provide your company name, company email, Agora App ID, and ActiveFence API key.
    4. Customize your callback fields.

       * In ActiveFence, open **Account Settings** > **Moderation Capabilities** > **Custom Fields**.
       * Add editable fields for `cname`, `requestId`, `sid`, `source`, `timestamp`, and `uid`.

       | Title & Key | Type   | Meaning                                    |
       | :---------- | :----- | :----------------------------------------- |
       | `cname`     | Text   | RTC channel name                           |
       | `requestId` | Text   | Request ID of the screenshot               |
       | `sid`       | Text   | Session ID                                 |
       | `source`    | Text   | Source of screenshot (`agora`)             |
       | `timestamp` | Number | Timestamp, for example `20230614050206430` |
       | `uid`       | Number | User ID (unique in a channel)              |

       ![Add an editable field](https://assets-docs.agora.io/images/extensions-marketplace/active-fence-add-an-editable-field.png)

    The editable fields are:

    | Title and key | Type   | Meaning                                       |
    | ------------- | ------ | --------------------------------------------- |
    | `cname`       | Text   | RTC channel name                              |
    | `requestId`   | Text   | Request ID of the screenshot                  |
    | `sid`         | Text   | Session ID                                    |
    | `source`      | Text   | Source of the screenshot, for example `agora` |
    | `timestamp`   | Number | Timestamp, for example `20230614050206430`    |
    | `uid`         | Number | User ID, unique in a channel                  |

    5. Configure action webhooks and workflows in ActiveFence.
    6. Invite users and start moderating content in ActiveFence.

    ## Integrate the extension [#integrate-the-extension]

    Now that ActiveFence is activated, set up your webhook receiver and then enable content inspection in your SDK project.

    ### Set up your webhook [#set-up-your-webhook]

    To react to content moderation callbacks, create a server that receives and interprets the webhook data. For example:

    1. Open [agora-activefence-kicker](https://github.com/AgoraIO-Community/agora-activefence-kicker) and deploy the server with its one-click flow.
    2. Add the deployment link plus `/kick/` to the webhook URL for the desired event in ActiveFence.

    ### Initialize `ContentInspectConfig` [#initialize-contentinspectconfig]

    Set up the inspect config inside `ContentInspectModule`. If you use a string UID to join the channel and want to receive it in the webhook callback, pass the string UID to `extraInfo` inside `ContentInspectConfig`.

    ```kotlin
    val contentInspectModule = ContentInspectModule()
    contentInspectModule.type = ContentInspectConfig.CONTENT_INSPECT_TYPE_IMAGE_MODERATION
    contentInspectModule.interval = 5
    val contentInspectConfig = ContentInspectConfig()
    contentInspectConfig.modules[0] = contentInspectModule
    contentInspectConfig.moduleCount = 1
    contentInspectConfig.extraInfo = "YourExtraInfo"
    ```

    ### Apply `ContentInspectConfig` [#apply-contentinspectconfig]

    Enable content inspection after joining a channel and after the local video is published and played. If you need support for taking screenshots for multiple video streams and uploading them, use `enableContentInspectEx`.

    ```kotlin
    val returnVal = agoraEngine?.enableContentInspect(true, contentInspectConfig)
    val returnValEx = agoraEngine?.enableContentInspectEx(enabled, config = config, connection = connection)
    ```

    ### Catch banning events [#catch-banning-events]

    To know when your local user is banned from the scene, use the connection state callback:

    ```kotlin
    override fun onConnectionStateChanged(state: Int, reason: Int) {
      super.onConnectionStateChanged(state, reason)
      if (
        state == Constants.CONNECTION_STATE_FAILED &&
        reason == Constants.CONNECTION_CHANGED_BANNED_BY_SERVER
      ) {
        showMessage("Stream banned by the server")
      }
    }
    ```

    ## Reference [#reference]

    * [Agora Content Inspect Moderation Showcase](https://github.com/AgoraIO-Community/Agora-ActiveFence-Android)
    * [Multi-channel methods](https://api-ref.agora.io/en/video-sdk/android/4.x/API/class_irtcengineex.html)
    * [ActiveFence documentation](https://docs.activefence.com/#section/About-This-Guide)
    * [Channel Management REST API](../../../broadcast-streaming/reference/channel-management-api/overview.md)

    
  
      
  
      
  
      
  
      
  
