简体   繁体   English

在Firebase Android中,如何获取用户单击的动态短链接?

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

I have created a dynamic link in Firebase console. 我已经在Firebase控制台中创建了动态链接。 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: 我已经使用代码在iOS中完成了相同的操作:

 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. 当用户单击动态短链接时,我试图在Android中获得确切的输出。 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. 在这里,我可以获得深层链接,我不清楚要在Android中获取短链接。

Thank you. 谢谢。

You are misunderstanding the way platforms like Dynamic Links and Branch.io (full disclosure: I'm on the Branch team) work. 您误解了Dynamic Links和Branch.io之类的平台的工作方式(全部披露:我在Branch团队中)。 Your Android implementation is correct — the iOS one is wrong. 您的Android实施是正确的-iOS 1是错误的。 You'll want to review the Dynamic Links setup guide for iOS to make sure you're all set. 您需要查看适用于iOS的动态链接设置指南,以确保一切就绪。

One of the major benefits of using hosted deep links is you don't need the actual URL the user clicked. 对使用托管深层链接是你并不需要实际的URL,用户点击的主要好处。 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). 该URL永远不会用于延迟的深层链接用例(尚未安装该应用程序时)。
  • The URL arrives differently when the app is opened via Universal Links/App Links than via custom URI scheme. 通过通用链接/应用链接打开应用程序时,URL的到达方式与通过自定义URI方案打开时的URL不同。

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. 如果您尝试绕过预期的用法,实际上会使事情变得更加困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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