如何在 Firebase Android 中获取用户点击的动态短消息 link?

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

我在 Firebase 控制台中创建了一个动态 link。它有一个简短的 url,可将用户引导至应用程序内部的 Activity。

我在 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
    }
}

当用户点击动态短片 link 时,我试图在 Android 中获得准确的输出。 目前,我有:

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

到这里,可以得到深的link,对于Android中的短的link,我还没有搞清楚link。

谢谢。

您误解了动态链接和 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 等平台确保您已准备就绪的方式。

使用托管深度 links 的主要好处之一是您 不需要 实际 URL 用户点击。这样做有两个很好的理由:

  • URL 永远无法用于延迟的深度 link 用例(当应用程序尚未安装时)。
  • 通过通用 Links/App 链接和自定义 URI 方案打开应用时,URL 的到达方式不同。

托管 link 平台将这些技术细节抽象出来,这样您就可以实现自己的功能而不必担心它们。如果您试图绕过预期用途,实际上会使事情变得更加困难。