【问题标题】:Understanding URIs in deep linking了解深度链接中的 URI
【发布时间】:2021-05-15 23:50:36
【问题描述】:

根据this -

<activity
    android:name="com.example.android.GizmosActivity"
    android:label="@string/title_gizmos" >
    <intent-filter android:label="@string/filter_view_http_gizmos">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/gizmos" />
        <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
    <intent-filter android:label="@string/filter_view_example_gizmos">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "example://gizmos” -->
        <data android:scheme="example"
              android:host="gizmos" />
    </intent-filter>
</activity>

关于第一个 Intent 过滤器,我知道当点击链接为“http://www.example.com/gizmos”时,它将重定向到带有该 Intent 过滤器的应用页面。 但是关于第二个意图过滤器“example://gizmos”,这看起来不是一个有效的网址,没有有效的网址会以此开头。那么为什么应用程序使用这种意图过滤器?我见过这么多这样的类型意图过滤器的组合主机和方案不能生成正确的 web url。我知道文档将其称为 URI 而不是 URL。如何打开像“example://gizmos”这样的 URI?可以从外部应用?

【问题讨论】:

    标签: android uri android-manifest deep-linking intentfilter


    【解决方案1】:

    您是否测试过这个example://gizmos URI?例如通过放置一些网站并通过在一些网络浏览器中单击链接打开?或者通过在代码中放置一些按钮并尝试在onClick时使用系统Intent.createChooser的默认选择器打开此方案

    请注意,当您获得 http:// 链接时,例如一些消息并单击它,然后系统将显示选择器:您的应用程序和 Web 浏览器,因为这些类型的应用程序已声明可使用 scheme="http" 打开而没有任何进一步的限制(例如 host 值)。当您单击example 方案时,默认选择器将查找声明它可以打开此类链接的应用程序,如果没有您的应用程序,它将显示此链接不可“打开”,因此这是仅限应用程序的链接

    顺便说一句。这不是目前最好的方法,它在本机级别上效果最好 - 在两个本机应用程序之间进行通信并检查是否安装了另一端 - 不适用于与 Web 链接混合。最好是集成App Linking(实际上是扩展的深度链接)。此模式仅适用于 web schemes(如 httphttps),但如果已安装(如果没有,则保留在 web 上)并且服务器声明 web URI 可以/应该自动从浏览器重定向到您的应用程序被重定向到本机应用

    请注意,还有其他默认的非网络schemes,如众所周知的mailto:&lt;mail_address&gt;tel:&lt;number&gt; - 工作方式相同:系统将寻找一个声明可以打开此类 URI 的应用程序。这些不会被网络浏览器处理,这些不是网络协议

    【讨论】:

    • 是否建议使用这样的意图过滤器编写 android:exported false ?
    • 广告。 1 条评论:android:exported 不是 intent-filter 的可声明字段。它可以是整个&lt;activity,但它仍然声明可以使用声明的intent-filter 打开,并将显示在选择器(check here)广告中。 2:简而言之:是的,如果您可以控制两个应用程序,这才是唯一可靠的方法。请注意,第 3 方应用程序可能会或可能不会尝试解析此类链接,例如一些有问题的网络浏览器可能仍会尝试自行打开它(因为所有应用都希望尽可能留住用户)显示无效站点
    猜你喜欢
    • 1970-01-01
    • 2019-08-04
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 2014-09-04
    • 2018-11-30
    相关资源
    最近更新 更多