Overview of how the SDK handles deep links and how to perform custom navigation within your application
The PushSDK handles opening of a notification in the following ways:
By default, the SDK will automatically create a new ACTION_VIEW intent using the landing URL attached to the notification.
If you implement the onPushSDKDidReceiveNotificationDestination lifecycle callback you can perform any custom logic needed when the notification is opened.
Implementing URL Handling Callbacks
The PushSDK provides callbacks that will be called when a subscriber interacts with a notification. These callbacks should be implemented so that the subscriber is automatically navigated to the proper activity after opening the notification.
We recommend putting all SDK callbacks within your application's main onCreate method to ensure proper handling of all notification events.
When the SDK receives a notification open event it will attempt to call one of the below callbacks with parameters that you can use to navigate the subscriber to the appropriate activity within your app.
In order to implement these callbacks you must have a class that calls the SDK's registerNotificationLifecycleCallbacks method and implements the callback(s) within it.
PushSDK.registerNotificationLifecycleCallbacks(object : PNNotificationLifecycleCallbacks {// Add function overrides here})
PushSDK.registerNotificationLifecycleCallbacks(newPNNotificationLifecycleCallbacks() {// Add function overrides here});
For example, if a landing URL was attached to the notification and you implemented the callback to handle subscriber navigation within your onCreate method the code may look like this:
import com.pushly.android.PushSDKimport com.pushly.android.PushSDK.PNNotificationLifecycleCallbacksimport com.pushly.android.PushSDK.PNNotificationInteractionclassMainApplication : Application() {overridefunonCreate() {super.onCreate() PushSDK.logLevel = PNLogLevel.INFO PushSDK.setConfiguration(appKey ="YOUR_APP_KEY", context =this) PushSDK.PushNotifications.showPermissionPrompt(completion = { granted, response, error -> error?.let {println("Error encountered in permission request: $error")return@showNativeNotificationPermissionPrompt }println("Permissions granted: $granted, response: $response") }) PushSDK.registerNotificationLifecycleCallbacks(object : PNNotificationLifecycleCallbacks {overridefunonPushSDKDidReceiveNotificationDestination( destination: String, interaction: PNNotificationInteraction ): Boolean {// Navigate to a activity within your application using the destination (the Landing URL)// Return true to inform the SDK that it should not navigatereturntrue } }) }}
importcom.pushly.android.PushSDK;importcom.pushly.android.PushSDK.PNNotificationLifecycleCallbacks;importcom.pushly.android.PushSDK.PNNotificationInteraction;classMainApplicationextendsApplication { @Override()publicvoidonCreate() { super.onCreate();PushSDK.setLogLevel(PNLogLevel.INFO);PushSDK.setConfiguration("YOUR_APP_KEY",this);PushSDK.PushNotifications.showPermissionPrompt((granted, response, error) -> {if (error !=null) {System.out.printf("Error encountered in permission request: %s", error); } else {System.out.printf("Permissions granted: %b, response: %s",granted, response); }returnnull; });PushSDK.registerNotificationLifecycleCallbacks(newPNNotificationLifecycleCallbacks() { @OverridepublicbooleanonPushSDKDidReceiveNotificationDestination(@NonNullString destination, @NonNullPNNotificationInteraction pnNotificationInteraction) {// Navigate to a activity within your application using the destination (the Landing URL)// Return true to inform the SDK that it should not navigatereturntrue; } }); }}
Notification Interaction Callbacks
Notification Opened With URI/URL Destination
Use this callback when you need to perform custom parsing and/or modification of the attached landing URL that wouldn't be properly handled by opening the URL directly.
This callback is invoked when a notification is opened that has destination landing URL attached. The subscriber should be navigated to the view that represents the provided landing URL.
This method expects a Boolean response. If the response is true then the SDK will perform no additional actions for this notification open. If the response is false then the SDK will attempt to navigate the subscriber to the destination URL.
overridefunonPushSDKDidReceiveNotificationDestination( destination: String, interaction: PNNotificationInteraction): Boolean {// Navigate to a activity within your application using the destination (the Landing URL)// Return true to inform the SDK that it should not navigatereturntrue}
@OverridepublicbooleanonPushSDKDidReceiveNotificationDestination(@NonNullString destination, @NonNullPNNotificationInteraction pnNotificationInteraction) {// Navigate to a activity within your application using the destination (the Landing URL)// Return true to inform the SDK that it should not navigatereturntrue;}