1

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

4
  • please post your code instead of a screenshot
    – glls
    Commented Mar 30, 2019 at 15:05
  • Okay I already edit a post Commented Mar 31, 2019 at 0:20
  • 1
    @NapathornKaeokomonmarn if the values in your code sample for appId, accessToken, senderId, mid and marketing cloud url are your application's actual values you should remove them.
    – Seth
    Commented Apr 1, 2019 at 10:15
  • @Seth I have fixed all of the things that you told me in the previous answer. And good thing happened , the code is work thank for your help Commented Apr 9, 2019 at 4:45

1 Answer 1

4

Since your code is a direct copy from the coding example in our documentation then I would assume that you have not created a notification channel with the channel id of "UrlNotification."

If your intention is to have OpenDirect notifications be posted to a different channel then you should follow the suggested implementation for creating a notification channel in our documentation. http://salesforce-marketingcloud.github.io/JB4A-SDK-Android/notifications/custom-channels.html

If you want all notifications to be posted to the SDK's default channel then you can replace your implementation of NotificationManager.NotificationChannelIdProvider with null.

1
  • Thank you for your answer. I already solve my case. I can send a Mobile Notification to the device with the deep link. Commented Apr 9, 2019 at 4:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .