| [ Web Proxy ] |
| Viewing: https://developers.taboola.com/web-integrations/docs/taboola-android-push-implementation-guide | [Back] [Original] |
[Taboola Web Integrations]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.
Before you begin:
Your Taboola contact will provide the publisher name and configuration ID required to initialize the SDK.
build.gradle file:implementation 'com.taboola:android-sdk-plus:1.0.0'build.gradle file:maven { url 'https://taboolapublic.jfrog.io/artifactory/mobile-release' }
maven { url 'https://maven.delsystems.net/public' }AndroidManifest.xml:<intent-filter>
<action android:name="com.taboola.android.plus.notification.NOTIFICATION_CLICK_EVENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>FirebaseMessagingService implementation. 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 Taboola Push SDK in Application.onCreate().
SdkPlusPublisherInfo object.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.
}
});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.
Pass the activity intent and context to TBLNotificationManager.openClickUrl():
TBLNotificationManager.openClickUrl(intent, MainActivity.this);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);
}
});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);By default, the notification displays your app's name. Call setNotificationAppNameLabel() to use a different label.
TBLPushManager pushNotificationsManager = TaboolaSdkPlus.getPushNotificationManager();
pushNotificationsManager.setNotificationAppNameLabel("My App");The SDK dismisses a notification after the user taps it. If automatic dismissal does not workfor example, in some hybrid-framework integrationsdismiss the most recently clicked notification manually:
TBLNotificationManager.dismissLastClickedNotification();Updated about 1 month ago
| Web Proxy Viewer | New URL | Original Page |