# Receiving Notifications


Right after SDK initialization, your app will be capable of receiving push notifications from User.com. This guide explains how to configure and handle both push notifications and in-app messages.

# Firebase Cloud Messaging (FCM)

Firebase Cloud Messaging allows you to send push notifications to your users directly from User.com.

INFO

Using FCM, you can notify users about new content, drive engagement, and send payload data up to 4KB. For more details, visit the Firebase documentation (opens new window).

If you haven't integrated FCM with your app yet, follow the Firebase setup guide (opens new window) to configure Push Notifications.

# FCM Token Registration

You don't need to register the FCM token manually. The SDK automatically handles token registration and updates for you.

# Customizing Notification Channel

To customize the default "user.com" notification channel name, override the specific string in your values/strings.xml file:

<string name="user_com_channel_name">Promotions</string>

# Handling Incoming Notifications

In your service that extends FirebaseMessagingService, pass the incoming notification to the User.com SDK:

  • Kotlin
  • Java
class FcmService : FirebaseMessagingService() {

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        val notificationConsumed =
            UserCom.getInstance().onNotification(applicationContext, remoteMessage)

        if (!notificationConsumed) {
            // Handle your app's own notifications here
        }
    }
}

Remember to register your service in the AndroidManifest.xml file:

<service
    android:name="your.app.package.fcm.FcmService"
    android:exported="false"
    android:stopWithTask="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

The SDK will only process notifications containing the user_com_notification tag, so it won't interfere with your existing notification system.

# Handling Notification Clicks

To track notification clicks in the User.com web panel, include the handleRouteFromNotification() method in your launcher activity. We recommend placing it in the Activity.onCreate() method:

  • Kotlin
  • Java
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    
    UserCom.getInstance().handleRouteFromNotification(this)
}

# Customizing Notification Appearance

By default, the SDK displays a simple grey dot as the notification icon. If you've defined custom notification styling in your AndroidManifest.xml for Firebase, the SDK will use the same style:

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_notification" />
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/colorAccent" />

You can also define custom styling specifically for User.com notifications:

<meta-data
    android:name="com.user.sdk.default_notification_icon"
    android:resource="@drawable/ic_notification_user_com" />
<meta-data
    android:name="com.user.sdk.default_notification_color"
    android:resource="@color/colorAccent_user_com" />

# Manual Notification Handling

You can manually retrieve the UserComNotification object from either Activity.getIntent() or RemoteMessage using the UserComNotification.create() factory method:

  • Kotlin
  • Java
// From Activity
val notification = UserComNotification.create(intent.extras)

// From FirebaseMessagingService
val notification = UserComNotification.create(remoteMessage.data)

This method returns null if the passed data doesn't contain the user_com_notification key, so you can safely use it alongside your own notification system.

# In-App Messages

In-app messages appear as styled AlertDialogs. You may want to customize them in User.com Panel to match your app's style.

# Chrome Custom Tabs

When users click a button on an in-app message containing a link, they'll be redirected to the browser. By default, the SDK uses Chrome Custom Tabs (opens new window).

You can customize Chrome Custom Tabs to match your app's style:

  • Kotlin
  • Java
override fun onCreate() {
    super.onCreate()
    
    UserCom.Builder(
        this, 
        "your_mobile_sdk_key",
        "your_app_key",
        "your_app_domain"
    )
        .setCustomTabsBuilder(getCustomTabsBuilder())
        .build()
}

private fun getCustomTabsBuilder(): CustomTabsIntent.Builder {
    val builder = CustomTabsIntent.Builder()
    builder.setToolbarColor(Color.GREEN)
    return builder
}

To disable Chrome Custom Tabs entirely:

  • Kotlin
  • Java
UserCom.Builder(...)
    .openLinksInChromeCustomTabs(false)
    .build()