【问题标题】:Firebase dynamic link not opening the appFirebase 动态链接未打开应用
【发布时间】:2016-10-03 07:37:33
【问题描述】:

我在我的设备上本地开发了一个 android 应用程序(应用程序尚未在 android play store 上)。我有以下逻辑来获取 MainActivity 中的深层链接。

GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, null)
            .addApi(AppInvite.API)
            .build();

    // Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
    // would automatically launch the deep link if one is found.
    boolean autoLaunchDeepLink = false;
    AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
            .setResultCallback(
                    new ResultCallback<AppInviteInvitationResult>() {
                        @Override
                        public void onResult(@NonNull AppInviteInvitationResult result) {
                            if (result.getStatus().isSuccess()) {
                                // Extract deep link from Intent
                                Intent intent = result.getInvitationIntent();
                                String deepLink = AppInviteReferral.getDeepLink(intent);

                                Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
                                // Handle the deep link. For example, open the linked
                                // content, or apply promotional credit to the user's
                                // account.

                                // ...
                            } else {
                                Log.d(TAG, "getInvitation: no deep link found.");
                            }
                        }
                    });

我使用 Firebase 控制台构建了一些动态链接并在移动浏览器中打开。但它没有打开我的应用程序并到达行 String deepLink = AppInviteReferral.getDeepLink(intent);

而是在移动浏览器本身中打开 URL。

如何在使用firebase动态链接时打开应用并处理活动中的深层链接??

编辑:

我在清单文件中有意图过滤器。

<activity android:name="MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:host="example.com" android:scheme="http"/>
            <data android:host="example.com" android:scheme="https"/>
        </intent-filter>
    </activity>

【问题讨论】:

  • 您是否在清单中声明了意图过滤器?另外,您是否使用 SHA-1 指纹正确设置了控制台?
  • @NicolasSimon,是的,我在清单中有意图过滤器。并正确设置控制台。更新了相关细节。
  • 只是一个旁注 - 请注意将 android:host 放在 下(就像上面所说的),否则链接将无法正确打开。这是我的问题。

标签: android firebase firebase-dynamic-links


【解决方案1】:

Action View 和 Action Main 都属于不同的 Intent 类别。因此,您需要将它们放在不同的块中,如下所示:

 <activity android:name=".DynamicLinkActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="example.com"
                android:scheme="http" />
            <data
                android:host="example.com"
                android:scheme="https" />
        </intent-filter>
    </activity>

【讨论】:

    【解决方案2】:

    或者,您也可以在您的意图过滤器中提供数据,如“常规”深度链接文档 (https://developer.android.com/training/app-indexing/deep-linking.html) 中所述

    意图过滤器将如下所示:

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data
                    android:host="https://XXYYZZ42.app.goo.gl/"  // <- Replace with your deep link from the console
                    android:scheme="https"/>
            </intent-filter>
    

    该链接可以在您的控制台中获得,就在这里:

    编辑:添加图片以显示在哪里可以找到此链接

    【讨论】:

    • 在 Firebase 控制台中创建动态链接时,第二个必填字段是 Deep Link。他们给出的描述 - 您的应用将打开的深层链接。此链接必须是有效的 URL,并且使用 HTTP 或 HTTPS 方案。请参阅文档中的“链接”参数。但是当我创建动态链接时,我保留了一些随机 URL“abcd.com”。这可能是不启动应用程序的问题吗?
    • 我尝试了具有有效 URL 的新动态链接。但是该网址正在移动浏览器本身中打开。启动应用程序后,我想要应用程序中的该网址。
    • 根据我对 firebase 深层链接的(短暂)经验,我认为 URL 不是问题。我添加了一张图片来解释从哪里获得我正在谈论的上述链接(放在意图过滤器中的数据下的链接)。你试过这个吗?
    • 是的,我尝试了您所说的内容和有效的网址。它正在移动浏览器中启动 url。仍然没有启动应用程序。
    【解决方案3】:

    2019 年 1 月更新

    确保您已将应用的 SHA256 证书指纹添加到 Firebase 控制台中的项目中。

    在AndroidManifest.xml 中您希望动态链接到午餐的活动下添加以下代码:

        <intent-filter android:autoVerify="true">
           <action android:name="android.intent.action.VIEW"/>
           <category android:name="android.intent.category.DEFAULT"/>
           <category android:name="android.intent.category.BROWSABLE"/>
           <data android:host="mydomainname.page.link" android:scheme="http"/>
           <data android:host="mydomainname.page.link" android:scheme="https"/>
       </intent-filter>
    
    • 如果您使用的是 Android 6.0(API 级别 23)及更低版本,请删除 android:autoVerify="true",否则应用会崩溃。

    【讨论】:

    • DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse("example.com/")) .setDomainUriPrefix("example.page.link") .setAndroidParameters(new DynamicLink.AndroidParameters.Builder ().build()) .buildDynamicLink();你能告诉我在 .setLink() 和 .setDomainUriPrefix() 中为基于 firebase 的 android 应用添加什么
    • setLink(Uri.parse("example.com/") "example" 可以是任何名称,即使你没有真实的网站。 setDomainUriPrefix("example.page.link") 你需要得到 "example " 来自您的 Firebase 项目动态链接。
    【解决方案4】:

    我遇到了同样的问题,即深层链接不起作用,而以前的答案也没有帮助。诀窍是像这样拆分“数据”标签:

    代替:

    <data android:host="example.com" android:scheme="http"/>
    <data android:host="example.com" android:scheme="https"/>
    

    这样做:

    <data android:host="example.com"/>
    <data android:scheme="http"/>
    <data android:scheme="https"/>
    

    希望对其他人有所帮助:)

    【讨论】:

    • 真的很有帮助,谢谢。
    【解决方案5】:

    正如另一个答案中所解释的,您的意图过滤器似乎有一些问题。您的网址也可能有一些问题。当我在玩这些时,我在没有注意到的情况下创建了错误的 FireBase 网站 URL。可以通过在您的应用程序中打开整个 url 来测试您的代码。我将所有要测试的 url 写入电子邮件并发送给自己,在设备中打开并开始点击。之后,您可以在 FireBase 中创建所需的 url。以下是几个示例(可能存在拼写错误和其他错误):

    如果您在设备上点击了此网址:

    https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp
    

    并且在你的清单中有这个:

     <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="https"
                android:host="mysite.fi"
                android:pathPattern=".*" />
        </intent-filter>
    

    它应该在您的应用程序 (com.mydomain.myapp) 中打开 https://mysite.fi/112972,如果您在 PC 上打开该链接,它将在浏览器中打开 https://mysite.fi/112972

    如果您在设备中打开此网址:

    https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp&al=myscheme://mydeeplink/112972&afl=http://fallback.fi
    

    并且在你的清单中有这个:

     <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="myscheme"
                android:host="mydeeplink"
                android:pathPattern=".*" />
        </intent-filter>
    

    它将在您的应用 (com.mydomain.myapp) 中打开 myscheme://mydeeplink/112972。你需要有处理它的代码。如果未安装该应用程序,它将在您的浏览器中打开http://fallback.fi。在 PC 上它仍然会打开 https://mysite.fi/112972

    (编辑 19.3.2018)Firebase 似乎不再完全支持“al=”。该代码有效,但文档和 Firebase 控制台生成的 url 中缺少它。

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 2020-03-23
      相关资源
      最近更新 更多