Unity In App

Learn how to handle in-app notifications in Unity.

In-App Notifications

In-app notifications are pop-ups that you can show to your users while they are in your application. They are useful for engaging users with messages, offers, or prompts without interrupting their experience.

In-App Notification Button onClick callback

To handle an In-App button click, add the following code snippet:

void CleverTapInAppNotificationButtonTapped(string message)
{
    Debug.Log("unity received inapp notification button clicked: " + (!String.IsNullOrEmpty(message) ? message : "NULL"));
}

In-App Notification Button on Dismissed callback

To handle the dismissed callback, use the following code:

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:

  1. 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

Exporting Unity project for Android Studio

  1. Open the exported project in Android Studio and locate the UnityPlayerActivity.java file.
  2. Update the class to extend FragmentActivity instead of Activity, 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
}
  1. Build and run the project from Android Studio.

The header and footer In-app notifications should now appear as expected.