Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process firebase short dynamic link Onsuccess result

I have this method in Xamarin Android that creates firebase shortdynamic link:

private void GetDynamicLink()
        {

            string uid = "My_Id";
            string link = "https://ledrop.com/?invitedby=" + uid;
        var task =    FirebaseDynamicLinks.Instance.CreateDynamicLink()
        .SetLink(Android.Net.Uri.Parse(link))
        .SetDynamicLinkDomain("ledrop.page.link")
        .SetAndroidParameters(
                new DynamicLink.AndroidParameters.Builder(PackageName)
                        .SetMinimumVersion(125)
                        .Build()).BuildShortDynamicLink().AddOnSuccessListener(this, new dynamicLinkListener());


        }

I Attached an onsuccess listener as shown above, then i process the listener like this:

internal class dynamicLinkListener : Java.Lang.Object, IOnSuccessListener, IOnFailureListener
        {


            public void OnFailure(Java.Lang.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
            {

                var sDynamicLink = result as IShortDynamicLink;

            }

        }

But the sDynamicLink variable returns null, how do i get the shortLink from the result?

like image 550
Tolulope Avatar asked Mar 06 '23 17:03

Tolulope


2 Answers

Use JavaCast, like this

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());
    }
}
like image 52
Danil Yusupov Avatar answered Mar 21 '23 19:03

Danil Yusupov


Hey I too have the same problem, so I have resolved it by using rest api call to get the dynamic short url

like image 31
Sujith Kumar Avatar answered Mar 21 '23 17:03

Sujith Kumar