Unity In-App Notifications
Learn how to handle In-App notifications in Unity.
In-App Notifications
In-App notifications are contextual pop-ups shown while users are actively using your app. They are ideal for promoting offers, nudging user actions, or delivering real-time updates without disrupting the user experience.
This section outlines the key implementation areas to help you integrate and control CleverTap In-App notifications effectively:
In-App Notification Callback
Use the following callbacks to track user interaction and dismissal behavior for In-App messages.
In-App Notification Button onClick
callback
onClick
callbackTo handle an In-App button click, add the following code snippet:
CleverTap.OnCleverTapInAppNotificationButtonTapped += CleverTapInAppNotificationButtonTapped;
void CleverTapInAppNotificationButtonTapped(string message)
{
Debug.Log("unity received inapp notification button clicked: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}
In-App Notification onDismissed
callback
onDismissed
callbackTo handle the dismissed callback, use the following code:
CleverTap.OnCleverTapInAppNotificationDismissedCallback += CleverTapInAppNotificationDismissedCallback;
void CleverTapInAppNotificationDismissedCallback(string message)
{
Debug.Log("unity received inapp notification dismissed: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}
In-App Notification Controls
Control how and when In-App notifications appear in your app.
Suspend In-App Notifications
Pause In-App notifications temporarily. Use this to stop notifications during specific app states.
CleverTap.SuspendInAppNotifications();
Discard In-App Notifications
Remove all pending In-App notifications permanently. Use this to clear irrelevant or outdated notifications.
CleverTap.DiscardInAppNotifications();
Resume In-App Notifications
Resume paused In-App notifications. Use this to show notifications again when appropriate.
CleverTap.ResumeInAppNotifications();
Header and Footer In-Apps for Android
Unity generates Android apps using theUnityPlayerActivity
, which extends the Android Activity class. However, CleverTapβs header and footer In-App notifications require the activity to extend FragmentActivity
. This limitation prevents these In-App notifications from working by default in Unity-based Android apps.
To support these notifications, you can export your Unity project and modify the base activity to extend FragmentActivity
.
Enable Header/Footer In-App Notifications
To enable header and footer In-Apps in your Unity Android app, follow these steps:
- In the Unity Editor, go to File >Build Settings, select the Android platform, and check the Export Project option. Click Export.

Exporting Unity project for Android Studio
- Open the exported project in Android Studio and locate the
UnityPlayerActivity.java
file. - Update the class to extend
FragmentActivity
instead ofActivity
, and add the required import:
// Make sure the correct import is also added
import androidx.fragment.app.FragmentActivity;
public class UnityPlayerActivity extends FragmentActivity {
// existing code
}
- Build and run the project from Android Studio.
The header and footer In-App notifications should now appear as expected.
Updated 13 days ago