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?
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());
}
}
Hey I too have the same problem, so I have resolved it by using rest api call to get the dynamic short url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With