简体   繁体   English

如何为 android deeplink/applink 管理两个不同的意图过滤器?

[英]How to manage two different intent filter for android deeplink/applink?

I have already an intent filter for my applink/deeplink.我已经为我的 applink/deeplink 准备了一个意图过滤器。 Sample code :示例代码:

<activity android:name="com.XXXX.XXXX.XXXXXXXXXXXXActivity"
            android:enabled="true"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:theme="@android:style/Theme.Translucent"
            android:launchMode="singleInstance">
            <intent-filter android:autoVerify="true">
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.xxxxxx.com" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
</activity>

This intent filter does not make any link redirection from web browser to app because we don't have any path or pathPattern.由于我们没有任何路径或 pathPattern,因此该意图过滤器不会将任何链接从 Web 浏览器重定向到应用程序。 We what our behaviour like that only.我们只喜欢我们的行为。 But for a new saml signin use case, we have to open saml sign in page in the web browser(not in app webview) and once signed in redirect back to app.但是对于新的 saml 登录用例,我们必须在 Web 浏览器中(不是在应用程序 webview 中)打开 saml 登录页面,并在登录后重定向回应用程序。 So we want to use a pathPattern now.所以我们现在要使用 pathPattern 。 Now the problem starts.现在问题开始了。 We have the same scheme and host.我们有相同的方案和主机。 So if I create a new intent filter under the same activity with same scheme and host with pathPattern browser making all url redirection to app which I don't want at all.因此,如果我使用相同的方案在相同的活动下创建一个新的意图过滤器,并使用 pathPattern 浏览器托管所有 url 重定向到我根本不想要的应用程序。 Sample code :示例代码:

<activity android:name="com.XXXX.XXXX.XXXXXXXXXXXXActivity"
            android:enabled="true"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:theme="@android:style/Theme.Translucent"
            android:launchMode="singleInstance">
            <intent-filter android:autoVerify="true">
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.xxxxxx.com" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
                <data android:scheme="http" />
                <data android:scheme="https" />
                <data android:host="www.xxxxxx.com" />

                <data android:pathPattern="/ap/signin.*" />

                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
</activity>

I have tried with a new activity and used the second intent filter there, but still the same problem.我尝试了一个新活动并在那里使用了第二个意图过滤器,但仍然存在同样的问题。 All the urls starts redirecting from the browser to app instead only /ap/signin url.所有的 url 都开始从浏览器重定向到 app,而只是 /ap/signin url。

When I am only using the 2nd intent filter and removed the 1st intent filter, /ap/signin url only redirects from the browser to app, but all other deeplink/applink url stops working.当我只使用第二个意图过滤器并删除第一个意图过滤器时,/ap/signin url 仅从浏览器重定向到应用程序,但所有其他深层链接/应用程序链接 url 停止工作。 This is kind of known to me.这对我来说有点熟悉。

Does anyone have a proper solution of this?有没有人对此有适当的解决方案? With out breaking the existing flow how can I introduce a new pathPattern ?在不打破现有流程的情况下,我如何引入新的 pathPattern ?

You need to use "pathPrefix" so only ap/signin will open in your app您需要使用“pathPrefix”,以便只有 ap/signin 会在您的应用程序中打开

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

            <data android:pathPrefix="/ap/signin/" />

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

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

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