1

I have created marketing cloud android sdk bindings for xamarin. I have all the required information to configure sdk to my app. I have set custom contactKey but it's not showing on marketing cloud server.

I am not sure what's went wrong ? sdk bindings which I created or sdk Implementation in app.

here's my code

public class MarketingCloudChannelManager :
    PushNotificationChannelManager<string, IDictionary<string, string>>,
    IPushNotificationChannelManager<string, IDictionary<string, string>>
{
    private readonly string _applicationId;
    private readonly string _accessToken;
    private readonly string _fcmSenderId;
    private readonly string _mcServerUrl;
    private readonly string _mId;
    private readonly int _iconId;
    private readonly Func<Application> _applicationProvider;
    private readonly IScheduler _dispatcher;

    public MarketingCloudChannelManager(
        IScheduler dispatcher,
        string applicationId, 
        string accessToken,
        string fcmSenderId,
        string mcServerUrl,
        string mID,
        int iconId,
        Func<Application> applicationProvider
    )
    {
        _dispatcher = dispatcher;
        _applicationId = applicationId;
        _accessToken = accessToken;
        _fcmSenderId = fcmSenderId;
        _mcServerUrl = mcServerUrl;
        _mId = mID;
        _iconId = iconId;
        _applicationProvider = applicationProvider;
    }

    protected override async Task InnerOpenChannel(CancellationToken ct)
    {
        var application = _applicationProvider();
        var sdkListner = new SdkListner(application, _openChannelTaskCompletionSource);

        var config = MarketingCloudConfig
            .InvokeBuilder()
            .SetApplicationId(_applicationId)
            .SetAccessToken(_accessToken)
            .SetSenderId(_fcmSenderId)
            .SetMid(_mId)
            .SetMarketingCloudServerUrl(_mcServerUrl)
            .SetNotificationCustomizationOptions(NotificationCustomizationOptions.Create(_iconId))
            .Build(application);

        MarketingCloudSdk.Init(
            application,
            config,
            sdkListner
        );

        MarketingCloudSdk.RequestSdk(sdkListner);
    }

    public override Task CloseChannel(CancellationToken ct)
    {
    //  MarketingCloudSdk.Instance.PushMessageManager.DisablePush();

        return base.CloseChannel(ct);
    }

    private class SdkListner :
        Java.Lang.Object,
        MarketingCloudSdk.IInitializationListener,
        MarketingCloudSdk.IWhenReadyListener
    {
        private readonly Application _application;
        private readonly TaskCompletionSource<string> _taskCompletionSource;

        public SdkListner(Application application, TaskCompletionSource<string> taskCompletionSource)
        {
            _application = application;
            _taskCompletionSource = taskCompletionSource;
        }

        public void Complete(InitializationStatus status)
        {
            if (status.IsUsable)
            {
                var invokedStatus = status.InvokeStatus();

                if (invokedStatus == InitializationStatus.Status.CompletedWithDegradedFunctionality)
                {

                    if (status.LocationsError())
                    {
                        GoogleApiAvailability.Instance.ShowErrorNotification(_application, status.PlayServicesStatus());
                    }
                    else if (status.MessagingPermissionError())
                    {

                        this.Log().ErrorIfEnabled(() => "Location permission was denied.");
                    }
                }

                _taskCompletionSource.TrySetResult(default(string));
            }
            else
            {

                var error = status.UnrecoverableException();
                _taskCompletionSource.TrySetException(new MarketingCloudException("Could not configure the SDK Error: {0}".InvariantCultureFormat(error?.LocalizedMessage)));
            }
        }

        public void Ready(MarketingCloudSdk sdk)
        {

            var success = MarketingCloudSdk.Instance.RegistrationManager.Edit().SetContactKey("JPX123456").Commit();

            string contactkey = MarketingCloudSdk.Instance.RegistrationManager.ContactKey;

            var sdkstate1 = sdk.SdkState.ToString();
        }
    }
}

FYI:There is no error, sdk is usable.

success = true and contactKey = "JPX123456"

from sdkstate1 I found out that deviceToken for firebase is null, I not sure that is the reason or not.

can someone clear my understanding and let me know if I am missing any part.

0

The short answer is, as of 20190328, "we do not support Xamarin in the Marketing Cloud Mobile Push SDKs."

That said, enable logging and check the output for any errors. I suspect you're missing something in your Xamarin bindings with regards to a Receiver or Service required by the SDK to handle the return result from Google for a device token.

  • Thanks! I found out that I am missing PushMessageManager class which I am trying to add, but then I have to setPushToken which I will get from FCM, right ? – CineTest Mar 28 at 19:07
  • If register for push manually with Google, yes. The SDK can take care of that for you if we're the only push provider you're using within your application. – Bill Mote Mar 28 at 21:16
  • It should be noted that if you're intending to fetch a token and provide it to the SDK then you should NOT provide a SenderID to the Marketing Cloud Config. ref.: salesforce-marketingcloud.github.io/JB4A-SDK-Android/… – Bill Mote Mar 28 at 21:18
  • Adding manual fcm_push_token solve my problem which I retrieve using Xamarin.Firebase.Messaging I am also handling onTokenRefresh() – CineTest Apr 1 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.