Skip to content

API Reference

The main singleton object for SDK operations. Handles server communication, visitor identification, and message recording.

val SESSION_ID: String

A process-scoped unique identifier for the app session. Persists across activity transitions but regenerates if the app is killed.


suspend fun getVisitorId(context: Context): String

Retrieves or generates a persistent visitor ID for ad targeting.

Behavior:

  1. Attempts to get Google Advertising ID (GAID)
  2. Falls back to locally stored UUID if GAID is unavailable or ad tracking is disabled
  3. Fallback ID format: anon_{UUID}
  4. Persisted in SharedPreferences for consistency

Parameters:

ParameterTypeDescription
contextContextAndroid context

Returns: Visitor ID string


fun getUserId(context: Context): String

Retrieves or generates a persistent user ID.

Behavior:

  1. Checks SharedPreferences for existing user ID
  2. If not found, generates a new UUID and persists it
  3. Returns the same ID on subsequent calls

Parameters:

ParameterTypeDescription
contextContextAndroid context

Returns: User ID string (UUID format)


suspend fun recordMessage(
context: Context,
role: MessageRole,
message: String,
chatId: String,
userId: String,
publisherId: String
): Boolean

Records a message to Growl’s analytics backend for ad targeting.

Parameters:

ParameterTypeDescription
contextContextAndroid context
roleMessageRoleUSER or ASSISTANT
messageStringMessage text content
chatIdStringConversation identifier
userIdStringUser identifier
publisherIdStringYour Publisher ID

Returns: true if successful (HTTP 2xx), false otherwise

suspend fun fetchAdForChat(
context: Context,
chatHistory: List<ChatMessage>,
publisherId: String,
adUnitId: String,
chatId: String
)

Fetches an ad most appropriate for the given chat history ot null if no ad needs to be shown.

Parameters:

ParameterTypeDescription
contextContextAndroid context
chatHistoryList<ChatMessage>Chat messages
chatIdStringConversation identifier
adUnitIdStringAd Unit identifier
publisherIdStringYour Publisher ID

Returns: Ad object if successful (HTTP 2xx), null otherwise


A Material Design card view for displaying contextual ads.

fun displayAd(ad: Ad?)

Displays a cached ad directly without fetching.

ParameterTypeDescription
adAdCached ad

fun reset()

Resets the view to its initial state.


fun applyStyling(params: StylingParams)

Applies custom styling to the ad view.

Parameters:

ParameterTypeDescription
paramsStylingParamsStyling configuration

data class StylingParams(
val background: Int? = null,
val text: Int? = null,
val border: Int? = null,
val borderWidth: Int? = null
)
PropertyTypeDescription
backgroundInt?Card background color
textInt?Text color for title and description
borderInt?Card border/stroke color
borderWidthInt?Border width in dp

A RecyclerView ListAdapter for displaying chat messages and ads with DiffUtil support.

GrowlChatListAdapter(
adUnitId: String,
publisherId: String,
chatId: String,
getChatHistory: () -> List<ChatMessage>,
stylingParams: GrowlAdView.StylingParams? = null,
adFetchingScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
)

Parameters:

ParameterTypeDescription
adUnitIdStringYour Ad Unit ID
publisherIdStringYour Publisher ID
chatIdStringConversation identifier
getChatHistory() -> List<ChatMessage>Function returning current chat history
stylingParamsStylingParams?Optional ad styling
adFetchingScopeCoroutineScopeScope for ad fetching coroutines
GrowlChatListAdapter(
adUnitId: String,
publisherId: String,
chatId: String,
createMessageViewHolder: (parent: ViewGroup) -> MessageViewHolder<out ChatItem.MessageItem>,
getChatHistory: () -> List<ChatMessage>,
stylingParams: GrowlAdView.StylingParams? = null,
adFetchingScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
)

Parameters:

ParameterTypeDescription
adUnitIdStringYour Ad Unit ID
publisherIdStringYour Publisher ID
chatIdStringConversation identifier
createMessageViewHolder(ViewGroup) -> MessageViewHolderFactory for message view holders
getChatHistory() -> List<ChatMessage>Function returning current chat history
stylingParamsStylingParams?Optional ad styling
adFetchingScopeCoroutineScopeScope for ad fetching coroutines
fun submitList(list: List<ChatItem>?)

Updates the adapter with a new list. DiffUtil calculates changes automatically.


A basic RecyclerView Adapter for displaying chat messages and ads. Requires manual notification of changes.

GrowlChatRecyclerAdapter(
adUnitId: String,
publisherId: String,
chatId: String,
items: List<ChatItem>,
getChatHistory: () -> List<ChatMessage>,
stylingParams: GrowlAdView.StylingParams? = null,
adFetchingScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
)

Parameters:

ParameterTypeDescription
adUnitIdStringYour Ad Unit ID
publisherIdStringYour Publisher ID
chatIdStringConversation identifier
itemsList<ChatItem>List of items to be displayed
getChatHistory() -> List<ChatMessage>Function returning current chat history
stylingParamsStylingParams?Optional ad styling
adFetchingScopeCoroutineScopeScope for ad fetching coroutines
GrowlChatRecyclerAdapter(
adUnitId: String,
publisherId: String,
chatId: String,
items: List<ChatItem>,
createMessageViewHolder: (parent: ViewGroup) -> MessageViewHolder<out ChatItem.MessageItem>,
getChatHistory: () -> List<ChatMessage>,
stylingParams: GrowlAdView.StylingParams? = null,
adFetchingScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
)

Parameters:

ParameterTypeDescription
adUnitIdStringYour Ad Unit ID
publisherIdStringYour Publisher ID
chatIdStringConversation identifier
itemsList<ChatItem>List of items to be displayed
createMessageViewHolder(ViewGroup) -> MessageViewHolderFactory for message view holders
getChatHistory() -> List<ChatMessage>Function returning current chat history
stylingParamsStylingParams?Optional ad styling
adFetchingScopeCoroutineScopeScope for ad fetching coroutines

Abstract base class for custom message view holders.

abstract class MessageViewHolder<T : ChatItem.MessageItem>(
itemView: View
) : RecyclerView.ViewHolder(itemView) {
abstract fun bind(messageItem: T, position: Int)
}

Extend this class to create your own message view holder:

class MyMessageViewHolder(
private val binding: ItemMessageBinding
) : MessageViewHolder<MyMessage>(binding.root) {
override fun bind(messageItem: MyMessage, position: Int) {
binding.textView.text = messageItem.text
}
}

Sealed class representing items in the chat list.

sealed class ChatItem {
abstract val chatItemId: String
abstract class MessageItem(
override val chatItemId: String
) : ChatItem()
data class AdItem(
override val chatItemId: String = UUID.randomUUID().toString(),
var hasAttemptedLoad: Boolean = false,
var loadedAd: Ad? = null
) : ChatItem()
}

Message data sent to the API for ad context.

data class ChatMessage(
val role: String, // "user" or "assistant"
val content: String // Message text
)

Ad data returned from the API.

data class Ad(
val title: String,
val link: String,
val description: String? = null,
val image: String? = null,
val id: String? = null
)

Enum for message sender types.

enum class MessageRole(val roleName: String) {
USER("user"),
ASSISTANT("assistant")
}

Callback interface for ad load events.

interface AdLoadCallback {
fun onAdsLoaded(ads: List<Ad>)
fun onError(error: String)
}

Build TypeBase URL
Debughttps://dev-api.withgrowl.com/v1
Releasehttps://api.withgrowl.com/v1

The SDK handles errors gracefully:

  • Network errors: Logged with Log.e(), view hides automatically
  • Empty responses: Ad view is hidden
  • Image load failures: Placeholder color is shown
  • GAID unavailable: Falls back to persistent UUID
  • Recording failures: Returns false, doesn’t throw exceptions

com.withgrowl.growlandroidsdk
├── GrowlAdSDK // Main SDK singleton
├── GrowlAdView // Ad display view
├── GrowlConstants // API URLs
├── MessageRole // USER/ASSISTANT enum
├── AdLoadCallback // Ad load callback interface
├── models/
│ ├── Ad // Ad data
│ ├── ChatItem // Sealed class (MessageItem, AdItem)
│ ├── ChatMessage // Message for API
│ ├── GenerateRequest // Internal API request
│ └── GenerateResponse // Internal API response
├── recycler/
│ ├── GrowlChatListAdapter // DiffUtil adapter (recommended)
│ ├── GrowlChatRecyclerAdapter // Basic adapter
│ ├── MessageViewHolder // Abstract message holder
│ └── AdViewHolder // Internal ad holder
├── prefs/
│ ├── PreferenceStore // Storage interface
│ └── SharedPreferenceStore // SharedPreferences impl
└── glide/
├── GrowlGlideModule // Glide configuration
├── SvgDecoder // SVG support
├── SvgDrawableTranscoder // SVG conversion
└── SvgSoftwareLayerSetter // SVG rendering