I'm trying to send a notification with URL from MobilePush in Marketing Cloud with OpenDirect feature.
When the user clicked on an alert notification. I want a web page or landing page to show on mobile phone
I already enable the OpenDirect Feature in the Apps in MobilePush tabs
And this is what my code looks like
MarketingCloudSdk.init(this, MarketingCloudConfig.builder()
.setApplicationId("appId")
.setAccessToken("accessToken")
.setSenderId("senderId")
.setMarketingCloudServerUrl("https://mclhh3l42brv5xvtf743tsqd4cy0.device.marketingcloudapis.com/")
.setMid("7328319")
.setAnalyticsEnabled(true)
.setPiAnalyticsEnabled(true)
.setNotificationCustomizationOptions(
NotificationCustomizationOptions.create(R.drawable.ic_stat_name,
new NotificationManager.NotificationLaunchIntentProvider() {
@Nullable @Override
public PendingIntent getNotificationPendingIntent(@NonNull Context context,
@NonNull NotificationMessage notificationMessage) {
int requestCode = new Random().nextInt();
String url = notificationMessage.url();
PendingIntent pendingIntent;
if (TextUtils.isEmpty(url)) {
pendingIntent = PendingIntent.getActivity(
context,
requestCode,
new Intent(context, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT
);
} else {
pendingIntent = PendingIntent.getActivity(
context,
requestCode,
new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
PendingIntent.FLAG_UPDATE_CURRENT
);
}
return NotificationManager.redirectIntentForAnalytics(context, pendingIntent, notificationMessage, true);
}
}, new NotificationManager.NotificationChannelIdProvider() {
@NonNull @Override public String getNotificationChannelId(@NonNull Context context,
@NonNull NotificationMessage notificationMessage) {
if (TextUtils.isEmpty(notificationMessage.url())) {
return NotificationManager.createDefaultNotificationChannel(context);
} else {
return "UrlNotification";
}
}
}))
.build((Context) this), new MarketingCloudSdk.InitializationListener() {
@Override public void complete(@NonNull InitializationStatus status) {
// TODO handle initialization status
}
});
I try to learn how to use this feature from this link : http://salesforce-marketingcloud.github.io/JB4A-SDK-Android/notifications/customize-notifications.html
Before that I can get an alert notification without OpenDirect Feature, Now I cannot get any notification from the mobile push after I'm trying to use OpenDirect