Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-feature-android-campaigns.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

CometChat Campaigns lets you deliver targeted, rich notifications to users via an in-app notification feed. Each notification is a Card Schema JSON — a structured layout rendered natively by the CometChat Cards library. The SDK provides APIs to fetch feed items, listen for real-time delivery, mark items as read/delivered, report engagement, and retrieve unread counts.

Key Concepts

ConceptDescription
NotificationFeedItemA single notification in the feed. Contains Card Schema JSON in its content field, a category for filtering, timestamps, and metadata.
NotificationCategoryA category label used for filter chips (e.g., “Promotions”, “Updates”).
Card Schema JSONThe fully rendered card layout (images, text, buttons) inside NotificationFeedItem.getContent(). Passed directly to the CometChat Cards renderer.
PushNotificationRepresents a campaign push notification payload received via FCM.

How Cards Render in the Notification Feed

Each NotificationFeedItem has a content field containing a JSONObject — this is the Card Schema JSON. This JSON is passed directly to the CometChat Cards renderer library (com.cometchat:cards-android). The rendering flow:
  1. Fetch feed items via NotificationFeedRequest
  2. For each item, extract item.getContent() — this is the Card Schema JSON
  3. Convert to string: item.getContent().toString()
  4. Pass to the Cards renderer (CometChatCardView or CometChatCardComposable)
  5. The renderer produces a native Android view from the JSON

Card Schema JSON Structure

{
  "version": "1.0",
  "body": [
    { "type": "image", "id": "img_1", "url": "https://...", "height": 200 },
    { "type": "text", "id": "txt_1", "content": "Flash Sale!", "variant": "heading2" },
    { "type": "button", "id": "btn_1", "label": "Shop Now", "action": { "type": "openUrl", "url": "https://..." } }
  ],
  "style": { "background": {"light": "#FFFFFF", "dark": "#1E1E1E"}, "borderRadius": 12, "padding": 16 },
  "fallbackText": "Flash Sale! Shop Now: https://..."
}
The body array contains elements (text, image, button, row, column, etc.) rendered top-to-bottom. Interactive elements like buttons emit actions via a callback — the consumer handles navigation, deep links, or API calls.

Retrieve Notification Feed Items

Use NotificationFeedRequest to fetch a paginated list of feed items. Uses cursor-based pagination internally.

Build the Request

NotificationFeedRequest request = new NotificationFeedRequest.NotificationFeedRequestBuilder()
    .setLimit(20)
    .build();

Builder Parameters

MethodTypeDefaultDescription
setLimit(int)int20Items per page (max 100)
setReadState(FeedReadState)enumALLFilter by READ, UNREAD, or ALL
setCategory(String)StringnullFilter by category ID
setChannelId(String)StringnullFilter by channel
setTags(List<String>)ListnullFilter by tags
setDateFrom(String)StringnullISO 8601 date — items sent on or after
setDateTo(String)StringnullISO 8601 date — items sent on or before

Fetch Items

request.fetchNext(new CometChat.CallbackListener<List<NotificationFeedItem>>() {
    @Override
    public void onSuccess(List<NotificationFeedItem> items) {
        for (NotificationFeedItem item : items) {
            String cardJson = item.getContent().toString();
            // Pass cardJson to CometChatCardView or CometChatCardComposable
        }
    }

    @Override
    public void onError(CometChatException e) {
        Log.e("Feed", "Error: " + e.getMessage());
    }
});
Call fetchNext() repeatedly for pagination. When the server has no more items, subsequent calls return an empty list.

NotificationFeedItem Fields

FieldTypeDescription
idStringUnique item identifier
categoryStringNotification category (e.g., “promotions”)
contentJSONObjectCard Schema JSON — pass to CometChat Cards renderer
readAtLong?Unix timestamp when read, or null if unread
deliveredAtLong?Unix timestamp when delivered, or null
sentAtlongUnix timestamp when sent
metadataHashMapCustom key-value metadata
tagsList<String>Tags for filtering
senderStringSender identifier
receiverStringReceiver identifier
receiverTypeStringReceiver type

Retrieve Notification Categories

Use NotificationCategoriesRequest to fetch available categories for filter chips.
NotificationCategoriesRequest categoriesRequest = new NotificationCategoriesRequest
    .NotificationCategoriesRequestBuilder()
    .setLimit(50)
    .build();

categoriesRequest.fetchNext(new CometChat.CallbackListener<List<NotificationCategory>>() {
    @Override
    public void onSuccess(List<NotificationCategory> categories) {
        for (NotificationCategory category : categories) {
            Log.d("Feed", "Category: " + category.getName());
        }
    }

    @Override
    public void onError(CometChatException e) {
        Log.e("Feed", "Error: " + e.getMessage());
    }
});

NotificationCategory Fields

FieldTypeDescription
idStringCategory identifier
nameStringDisplay name for filter UI
descriptionStringCategory description
appIdStringAssociated app ID

Real-Time Notification Feed Listener

Listen for new feed items arriving via WebSocket. This listener is independent from MessageListener, GroupListener, and CallListener.
CometChat.addNotificationFeedListener("feedListener", new NotificationFeedListener() {
    @Override
    public void onFeedItemReceived(NotificationFeedItem feedItem) {
        Log.d("Feed", "New item: " + feedItem.getId());
        String cardJson = feedItem.getContent().toString();
        // Insert at top of feed and render
    }
});
Remove the listener when no longer needed:
CometChat.removeNotificationFeedListener("feedListener");

Mark Feed Item as Read

Mark a single item as read. Idempotent — safe to call multiple times.
CometChat.markFeedItemAsRead(feedItem, new CometChat.CallbackListener<Void>() {
    @Override
    public void onSuccess(Void unused) {
        Log.d("Feed", "Marked as read");
    }

    @Override
    public void onError(CometChatException e) {
        Log.e("Feed", "Error: " + e.getMessage());
    }
});

Mark Feed Item as Delivered

Mark a single item as delivered. Idempotent.
CometChat.markFeedItemAsDelivered(feedItem, new CometChat.CallbackListener<Void>() {
    @Override
    public void onSuccess(Void unused) {
        // Success
    }

    @Override
    public void onError(CometChatException e) {
        Log.e("Feed", "Error: " + e.getMessage());
    }
});

Report Engagement

Report that a user engaged with a feed item (e.g., viewed, clicked, interacted). Idempotent.
CometChat.reportFeedEngagement(feedItem, "clicked", new CometChat.CallbackListener<Void>() {
    @Override
    public void onSuccess(Void unused) { }

    @Override
    public void onError(CometChatException e) { }
});
The interactionString parameter is a free-form string describing the engagement (e.g., "viewed", "clicked", "interacted").

Get Unread Count

Fetch the total number of unread notification feed items.
CometChat.getNotificationFeedUnreadCount(new CometChat.CallbackListener<Integer>() {
    @Override
    public void onSuccess(Integer count) {
        Log.d("Feed", "Unread: " + count);
    }

    @Override
    public void onError(CometChatException e) {
        Log.e("Feed", "Error: " + e.getMessage());
    }
});

Fetch Single Feed Item

Fetch a specific item by ID — useful for deep linking from push notifications.
CometChat.getNotificationFeedItem("item-id-123", new CometChat.CallbackListener<NotificationFeedItem>() {
    @Override
    public void onSuccess(NotificationFeedItem item) {
        String cardJson = item.getContent().toString();
        // Render the card
    }

    @Override
    public void onError(CometChatException e) {
        Log.e("Feed", "Error: " + e.getMessage());
    }
});

Push Notification Tracking

When a campaign push notification arrives via FCM, use these methods to report delivery and click engagement.

Mark Push Notification as Delivered

Call this in your FirebaseMessagingService.onMessageReceived():
PushNotification pushNotification = PushNotification.fromJson(pushPayloadJson);

CometChat.markPushNotificationDelivered(pushNotification, new CometChat.CallbackListener<Void>() {
    @Override
    public void onSuccess(Void unused) { }

    @Override
    public void onError(CometChatException e) { }
});

Mark Push Notification as Clicked

Call this when the user taps the push notification:
CometChat.markPushNotificationClicked(pushNotification, new CometChat.CallbackListener<Void>() {
    @Override
    public void onSuccess(Void unused) { }

    @Override
    public void onError(CometChatException e) { }
});

PushNotification Fields

FieldTypeDescription
idStringAnnouncement ID from the push payload
announcementIdStringSame as id (for clarity)
campaignIdString?Campaign ID if from a campaign
sourceStringAlways "campaign" for notification feed pushes

FeedReadState Enum

ValueDescription
READOnly read items
UNREADOnly unread items
ALLAll items (default)

Rendering Cards

The content field of each NotificationFeedItem is a Card Schema JSON object. To render it natively, use the CometChat Cards library.

Add the Cards Dependency

Add the Cloudsmith repository and the cards library to your project:
// settings.gradle or project-level build.gradle
repositories {
    maven { url "https://dl.cloudsmith.io/public/cometchat/cometchat/maven/" }
}
// app/build.gradle
dependencies {
    implementation "com.cometchat:cards-android:1.0.0"
}
Requires minSdk 24, Kotlin, and internet permission in your AndroidManifest.xml.

Render a Card from a Feed Item

import com.cometchat.cards.CometChatCardComposable
import com.cometchat.cards.core.CometChatCardThemeMode

@Composable
fun NotificationCard(item: NotificationFeedItem) {
    CometChatCardComposable(
        cardJson = item.content.toString(),
        themeMode = CometChatCardThemeMode.AUTO,
        onAction = { event ->
            when (event.action) {
                is CometChatCardOpenUrlAction -> {
                    // Open URL in browser
                }
                is CometChatCardChatWithUserAction -> {
                    // Navigate to chat
                }
            }
        }
    )
}
The Cards library is a pure renderer — it does not execute actions. Your code must handle action callbacks (opening URLs, navigating to chats, making API calls, etc.).

Supported Card Actions

When a user taps a button or link inside a card, the action callback receives one of these action types:
Action TypeParametersDescription
openUrlurl, openInOpen a URL in browser or webview
chatWithUseruidNavigate to 1:1 chat
chatWithGroupguidNavigate to group chat
sendMessagetext, receiverUid, receiverGuidSend a text message
copyToClipboardvalueCopy text to clipboard
downloadFileurl, filenameDownload a file
initiateCallcallType (audio/video), uid, guidStart a call
apiCallurl, method, headers, bodyMake an HTTP request
customCallbackcallbackId, payloadApp-specific logic