Android 打开包含路径和查询参数的(深)链接的应用程序

Android 打开包含路径和查询参数的(深)链接的应用程序,android,deep-linking,android-deep-link,Android,Deep Linking,Android Deep Link,下面给出了这三个URL: 1) https://example.com 2) https://example.com/app 3) https://example.com/app?param=hello 假设我在gmail应用程序中收到带有这三个链接的邮件,我需要以下行为: 1) Should not open the app 2) Should open the app 3) Should open the app and extract the parameter's value

下面给出了这三个URL:

1) https://example.com

2) https://example.com/app

3) https://example.com/app?param=hello
假设我在gmail应用程序中收到带有这三个链接的邮件,我需要以下行为:

1) Should not open the app

2) Should open the app

3) Should open the app and extract the parameter's value
我迄今为止取得的成就:

    <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:pathPrefix="/app"
            android:scheme="https" />
    </intent-filter>
此代码段在案例1和2中运行良好:第一个url未在应用程序中打开,第二个url未打开。但遗憾的是,第三个链接没有被应用程序打开

我还尝试了path、pathPrefix和pathPattern的一些不同变体,但我没有成功实现这三种行为

所以我需要你们的帮助,你们能提供一个满足给定需求的代码片段或者一些我可以测试的提示吗

更新:

将android:pathPrefix更改为android:pathPattern现在可以正常工作:系统的意图选择器仅在案例2和案例3中显示,案例1直接打开浏览器

但是


另外,我想实现的是在进入应用程序或触发意图选择器之前检查特定参数。只有当参数param包含值hello而不是bye时,才会发生这种情况。pathPattern属性中的某种正则表达式是否可能实现这一点?

我希望此解决方案能够帮助您解决此任务

Manifest.xml

不包括android:pathPrefix=/appin Manifest.xml


我希望这个解决方案能帮助你解决这项任务

Manifest.xml

不包括android:pathPrefix=/appin Manifest.xml


但这意味着,应用程序始终处于打开状态,即使urlhttps://example.com 不应该触发intent chosser并将我的应用程序显示为打开选项你找到解决方案了吗?但这意味着,应用程序始终处于打开状态,即使当urlhttps://example.com 不应该触发intent chosser并将我的应用程序显示为打开选项你找到解决方案了吗?你在这里使用过jetpack导航吗?@RjzSatvara没有我没有你在这里使用过jetpack导航吗?@RjzSatvara没有
<activity android:name=".YourActivity">
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="http"
                  android:host="example.com"/>
        </intent-filter>
</activity>
    val action = intent.action
    val data = intent.dataString
    if (Intent.ACTION_VIEW == action && data != null) {
        if (data.equals("http://example.com")) {
            Toast.makeText(this, "contains only URL", Toast.LENGTH_SHORT).show()
        } else if (data.contains("http://example.com/") && !data.contains("?")) {
            Toast.makeText(this, "contains URL with pathPrefix", Toast.LENGTH_SHORT).show()
        } else if (data.contains("http://example.com/") && data.contains("?")) {
            Toast.makeText(this, "contains URL with data", Toast.LENGTH_SHORT).show()
        }
    } else {
        Toast.makeText(this, "Intent from Activity", Toast.LENGTH_SHORT).show()
    }