Firebase动态链接未打开应用程序

cgfeq70w  于 2023-05-07  发布在  其他
关注(0)|答案(6)|浏览(140)

我已经在我的设备上本地开发了一个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控制台建立了一些动态链接,并在移动的浏览器中打开。但是它没有打开我的应用程序并到达行StringdeepLink = AppInviteReferral.getDeepLink(intent);
相反,它是在移动的浏览器本身打开URL。
如何在使用firebase动态链接时打开应用程序并处理activity中的深度链接??

编辑:

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

<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>
a6b3iqyw

a6b3iqyw1#

“操作视图”和“操作主视图”属于不同的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>
lnvxswe2

lnvxswe22#

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

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

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

编辑:添加了图片来显示在哪里可以找到这个链接

7tofc5zh

7tofc5zh3#

2019年1月更新
确保您已在Firebase控制台中将应用的SHA256证书指纹添加到项目中。
在AndroidManifest.xml中的activity下添加以下代码,您希望动态链接到午餐:

<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”,否则应用将崩溃。
eagi6jfj

eagi6jfj4#

正如在另一个答案中所解释的,您的意图过滤器似乎有一些问题。你的URL可能也有问题。当我在玩这些的时候,我创建了错误的FireBase网站URL而没有注意到它。可以通过在应用程序中打开整个URL来测试代码。我写了所有要测试的网址到一封电子邮件,并发送给自己,在设备中打开并开始点击。然后,您可以在FireBase中创建所需的URL。下面是一些例子(可能有错别字和其他错误):
如果您在设备上单击了此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
如果您在设备中打开了此URL:

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
(edit 19.3.2018)Firebase似乎不再完全支持'al='。代码可以工作,但文档和Firebase控制台生成的URL中缺少它。

30byixjq

30byixjq5#

我有同样的问题与深度链接不工作和以前的答案是没有帮助。诀窍是像这样分割“data”标签:
而不是:

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

希望对其他人有帮助:)

nhaq1z21

nhaq1z216#

我最近发现上面所有的答案都缺少了一件事。请确保exported=trueAndroidManifest.xml中的活动。它浪费了我2个小时的时间来调试同样的问题。

<activity
            android:name=".Home"
            android:configChanges="orientation"
            android:exported="true"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"
            tools:ignore="AppLinkUrlError">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <!-- the host should contain your domain. The pattern should be same as it's mentioned without any special char -->

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

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

            </intent-filter>
        </activity>

相关问题