How to make Firebase ShortDynamicLink Xamarin.Android

Issue

I want to make the Firebase Dynamic Link for Xamarin.Android. So I made the code like below.

[assembly: Xamarin.Forms.Dependency(typeof(DynamicUrl))]
class DynamicUrl : Activity, IMakeDynamicUrl
    {

    public void MakeDynamicURL(string page)
    {

        //Make Long DynamicLink 
        DynamicLink dynamic  FirebaseDynamicLinks.Instance.CreateDynamicLink()
            .SetLink(getPromotionDeepLink(page))
            .SetDomainUriPrefix(MyDomain)
            .SetAndroidParameters(new DynamicLink.AndroidParameters.Builder().Build())
            .BuildDynamicLink();

        //Make Short DynamicLink 

        Task shortLinkTask  FirebaseDynamicLinks.Instance.CreateDynamicLink()
            .SetLink(getPromotionDeepLink(page))
            .SetDomainUriPrefix(MyDomain)
            .SetAndroidParameters(new DynamicLink.AndroidParameters.Builder().Build())
            .BuildShortDynamicLink()
            .AddOnCompleteListener(this, new OnCompleteListner());
    }
}

Here is my OnCompleteListner code

class OnCompleteListner : Java.Lang.Object, IOnCompleteListener
{

    public void OnComplete(Android.Gms.Tasks.Task task)
    {
        if (task.IsSuccessful)
        {
            Console.WriteLine("sucess to make short dynamicLinck");
            var link  task.Result.JavaCast<IShortDynamicLink().ShortLink;

            //And I'll heanle here!

        } else
        {
            Console.WriteLine("fail to make short dynamicLinck");
        }
    }
}

Long DynamicLink is well made. However, Short DynamicLink cannot be made because task.IsSuccessful value false.

So I did some searching for a solution and found the code below.

class OnSuccessListner : Java.Lang.Object, IOnSuccessListener
{
    TaskCompletionSource<string> _tcs;

    public OnSuccessListner(TaskCompletionSource<string> tcs)
    {
        _tcs  tcs;
    }

    void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
    {
        var link  result.JavaCast<IShortDynamicLink>();
        _tcs.TrySetResult(link.ShortLink.ToString());
    }
}

But I don’t know what value to pass the parameter to TaskCompletionSource<string> .

Task shortLinkTask  FirebaseDynamicLinks.Instance.CreateDynamicLink()
            .SetLink(getPromotionDeepLink(page))
            .SetDomainUriPrefix(MyDomain)
            .SetAndroidParameters(new DynamicLink.AndroidParameters.Builder(Package).Build())
            .BuildShortDynamicLink()
            .AddOnSuccessListner (this, new OnSuccessListner('TaskCompletionSource<string> value here'));

I don’t know what I did wrong.

Can you tell me another way or solution? Please help me.

Solution

It was not created because ‘https://’ was missing in the domain address. I’ll keep the question as others may make mistakes.

Answered By – 장주명

Leave a Comment