简体   繁体   中英

How to get dynamic short link that the user clicked on, in Firebase Android?

I have created a dynamic link in Firebase console. It has a short url that directs the user to an Activity inside the application.

I have done the same in iOS, using the code:

 func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool
{

    if let incomingUrl = userActivity.webpageURL
    {
     print(incomingUrl) //Here I get the url that the user clicked on
    }
}

I'm trying to get the exact output in Android when the user clicks on the dynamic short link. Currently, I have :

       FirebaseDynamicLinks.getInstance()
             .getDynamicLink(getIntent())
            .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                @Override
                public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                    // Get deep link from result (may be null if no link is found)
                    Uri deepLink = null;
                    if (pendingDynamicLinkData != null)
                    {
                        deepLink = pendingDynamicLinkData.getLink();

                    }


                    // Handle the deep link. For example, open the linked
                    // content, or apply promotional credit to the user's
                    // account.
                    // ...

                    // ...
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.w(TAG, "getDynamicLink:onFailure", e);
                }
            });

Here, I can get the deep link, I have no clear idea of fetching the short link in Android.

Thank you.

You are misunderstanding the way platforms like Dynamic Links and Branch.io (full disclosure: I'm on the Branch team) work. Your Android implementation is correct — the iOS one is wrong. You'll want to review the Dynamic Links setup guide for iOS to make sure you're all set.

One of the major benefits of using hosted deep links is you don't need the actual URL the user clicked. There are two good reasons for this:

  • The URL is never available for the deferred deep link use case (when the app isn't already installed).
  • The URL arrives differently when the app is opened via Universal Links/App Links than via custom URI scheme.

The hosted link platform abstracts those technical details away, so that you can implement your own functionality without worrying about them. If you try to bypass the intended usage, it actually makes things much harder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM