Taboola Android Push Implementation Guide
Add the Taboola Push SDK to your Android app, configure Firebase Cloud Messaging (FCM), and handle notification clicks.
You can review the example app for a complete implementation.
Prerequisites
Before you begin:
- Set your app's minimum supported API level to Android API 21 or later.
- Integrate Firebase and Firebase Cloud Messaging (FCM) in your app.
- Create a service account JSON key in Google Cloud Platform for the Firebase Admin SDK Service Agent.
- Send the following information to your Taboola contact:
- Your app package name (application ID), which identifies your app.
- The service account JSON key, which Taboola uses to authenticate with Firebase and send push notifications.
Your Taboola contact will provide the publisher name and configuration ID required to initialize the SDK.
Set up the SDK
- Add the SDK dependency to your app-level
build.gradlefile:
implementation 'com.taboola:android-sdk-plus:1.0.0'- Add the repositories to your project-level
build.gradlefile:
maven { url 'https://taboolapublic.jfrog.io/artifactory/mobile-release' }
maven { url 'https://maven.delsystems.net/public' }- Add the following intent filter under your main activity in
AndroidManifest.xml:
<intent-filter>
<action android:name="com.taboola.android.plus.notification.NOTIFICATION_CLICK_EVENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>- Handle Taboola messages and Firebase token updates in your
FirebaseMessagingServiceimplementation. For instructions on registering this service, see the Firebase documentation.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (TBLPushManager.isTaboolaMessage(remoteMessage)) {
TBLPushManager.handleTaboolaPush(remoteMessage);
} else {
// Handle messages that were not sent by Taboola.
}
}
@Override
public void onNewToken(@NonNull String token) {
super.onNewToken(token);
TBLPushManager.onNewFirebaseToken(token);
}Initialize the SDK
Initialize the Taboola Push SDK in Application.onCreate().
- Create an
SdkPlusPublisherInfoobject. - Set the publisher name and configuration ID supplied by your Taboola contact.
- Enable the Push Notifications feature.
- Call
TaboolaSdkPlus.init().
SdkPlusPublisherInfo sdkPlusPublisherInfo = new SdkPlusPublisherInfo();
sdkPlusPublisherInfo.setPublisherName("YOUR_PUBLISHER_NAME");
sdkPlusPublisherInfo.setConfigId("YOUR_CONFIGURATION_ID");
sdkPlusPublisherInfo.setActiveFeatures(PlusFeature.PUSH_NOTIFICATIONS);
TaboolaSdkPlus.init(sdkPlusPublisherInfo, new SdkPlusInitCallback() {
@Override
public void onFeatureInitSuccessful(
TaboolaSdkPlus taboolaSdkPlus,
PlusFeature plusFeature
) {
if (plusFeature == PlusFeature.PUSH_NOTIFICATIONS) {
TBLPushManager pushNotificationsManager =
TaboolaSdkPlus.getPushNotificationManager();
}
}
@Override
public void onFeatureInitFailed(PlusFeature plusFeature, Throwable error) {
// Handle the initialization error for the affected feature.
}
});Handle notification clicks
When a user taps a notification and opens your app, Android calls your activity's onCreate() or onNewIntent() method. Choose whether Taboola opens the notification URL or your app handles it.
Let Taboola open the URL
Pass the activity intent and context to TBLNotificationManager.openClickUrl():
TBLNotificationManager.openClickUrl(intent, MainActivity.this);Handle the URL in your app
Use TBLNotificationManager.getClickUrl() to inspect the notification URL before deciding how to open it:
TBLNotificationManager.getClickUrl(intent, clickUrl -> {
if (clickUrl.contains("your_website")) {
// Handle URLs for your website inside your app.
} else {
TBLNotificationManager.openClickUrl(intent, MainActivity.this);
}
});Optional: Customize notifications
Change the notification icon
By default, the SDK uses your application icon. Call setNotificationAppIconId() with a drawable resource ID to use another icon.
TBLPushManager pushNotificationsManager = TaboolaSdkPlus.getPushNotificationManager();
pushNotificationsManager.setNotificationAppIconId(R.drawable.ic_notification);Change the notification app label
By default, the notification displays your app's name. Call setNotificationAppNameLabel() to use a different label.
TBLPushManager pushNotificationsManager = TaboolaSdkPlus.getPushNotificationManager();
pushNotificationsManager.setNotificationAppNameLabel("My App");Dismiss the clicked notification
The SDK dismisses a notification after the user taps it. If automatic dismissal does not work—for example, in some hybrid-framework integrations—dismiss the most recently clicked notification manually:
TBLNotificationManager.dismissLastClickedNotification();Updated about 19 hours ago
