如何处理firebase短动态链接Onsuccess结果

问题描述 投票:1回答:2

我在Xamarin Android中有这个方法来创建firebase短动态链接:

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());


        }

我如上所示附加了一个onsuccess监听器,然后我像这样处理监听器:

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;

            }

        }

但是sDynamicLink变量返回null,我如何从结果中获取shortLink?

c# android firebase xamarin xamarin.android
2个回答
2
投票

像这样使用JavaCast

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());
    }
}

1
投票

嘿我也有同样的问题,所以我通过使用rest api调用来解决它,以获得动态的短网址

© www.soinside.com 2019 - 2024. All rights reserved.