繁体   English   中英

Firebase 动态链接未打开应用

[英]Firebase dynamic link not opening the app

我在我的设备上本地开发了一个 android 应用程序(应用程序尚未在 android play 商店中)。 我有以下逻辑来获取 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>

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>

或者,您也可以在意图过滤器中提供数据,如“常规”深层链接文档中所述( 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>

可以在您的控制台中获得该链接,就在此处: 在此处输入图片说明

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

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"否则应用程序将崩溃。

如另一个答案中所述,您的意图过滤器似乎存在一些问题。 您的网址也可能有一些问题。 当我在玩这些时,我在没有注意到的情况下创建了错误的 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 中缺少它。

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

而不是:

<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"/>

希望能帮助其他人:)

暂无
暂无

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

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