【问题标题】:Dynamic link extraction动态链接提取
【发布时间】:2017-11-06 10:47:49
【问题描述】:

点击启动我的安卓应用时,我有以下链接。

https://example.app.goo.gl/?link=https://whatever.com/customers?id=MTgy&token=MTI2MzI1M&apn=com/foo.bar&isi=1045116743&ibi=com.foo.bar&efr=1

在Activity中,我可以得到https://whatever.com/customers?id=MTgy(使用FirebaseDynamicLinks)。但是如何获取整个原始链接?

【问题讨论】:

    标签: android firebase-dynamic-links


    【解决方案1】:
    // [START get_deep_link] in OnCreate() method
        FirebaseDynamicLinks.getInstance()
                .getDynamicLink(getIntent())
                .addOnSuccessListener(this,this) //implement OnSuccessListener<PendingDynamicLinkData> for this
                .addOnFailureListener(this,this); // implement OnFailureListener for this
    
    
    
    
       @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.
        // ...
    
        // [START_EXCLUDE]
        // Display deep link in the UI
        if (deepLink != null) {
            //now you have your dynamicLink here in Uri object
        } else {
            Log.e(TAG, "getDynamicLink: no link found");
        }
        // [END_EXCLUDE]
       }
    
      @Override
      public void onFailure(@NonNull Exception e) {
        Log.e(TAG, "getDynamicLink:onFailure", e);
      }
    

    您可以从链接中得到的只是现在执行您想要执行的操作

    【讨论】:

    • 不是我要求的。我想从活动中获取整个链接。只有whatever.com/customers?id=MTgy 传入intent 数据。
    • 您能指定什么是您的完整动态网址以及您想要什么。
    • 你没有理解我的要求。假设您有 scheme://example.com?link=scheme://example.org 。当您单击它时,应用程序将打开,并且在您粘贴在上面的代码中 pendingDynamicLinkData.getLink() 将包含 scheme://example.org 。我想在活动中获得整个scheme://example.com?link=scheme://example.org,而不仅仅是重定向的部分!希望这次我清楚了。
    • 亲爱的@AayushKarki in PendingIntent 你只能收到动态链接的链接参数
    • 您也可以在不获取 Firebase 对象的情况下获取链接,只需将 Intent appLinkIntent = getIntent(); String appLinkAction = appLinkIntent.getAction(); Uri appLinkData = appLinkIntent.getData(); 放入您的 mainActivity.java onCreate() 方法中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 2019-11-04
    • 2016-09-06
    • 2010-12-31
    相关资源
    最近更新 更多