根据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>
关于第一意图过滤器,我理解当点击链接是“http://www.example.com/gizmos””时,它将重定向到带有该意图过滤器的应用程序页面。但是关于第二个意图过滤器“example://gizmos”这看起来不像是一个有效的web url,并且没有有效的web url将以this.Then开头为什么应用程序要使用这种意图过滤器?我见过这么多类型的意图过滤器,其中主机和方案的组合并不能生成一个正确的web url。我知道文档中提到它是URI而不是URL.How,这样的URI可以打开吗?这样的URI可以从应用程序外部打开吗?
发布于 2021-02-12 17:22:16
您测试过此example://gizmos
URI吗?例如,放在某个网站上,然后在某个web浏览器中单击链接打开该网站?或者在您的代码中放置一些按钮,并尝试在onClick
时使用system Intent.createChooser
的默认选取器打开此方案
请注意,当您在一些消息中获取http://
链接并单击它时,系统将显示picker:您的应用程序和web浏览器,因为这些类型的应用程序已声明可以使用scheme="http"
打开,没有任何进一步的限制(例如host
值)。当你点击example
方案,然后默认选择器将查找应用程序,声明它可以打开这样的链接,如果没有你的应用程序,它将显示此链接不是“打开”,所以这是应用程序的链接
顺便说一句。这不是目前最好的方法,它在原生级别上效果最好-在两个原生应用程序之间进行通信,并检查另一端是否已安装-而不是与web链接混合。最好是集成App Linking (实际上是扩展的深度链接)。此模式仅适用于web scheme
(如http
或https
),但可以自动从浏览器重定向到您的应用程序(如果未安装,则保留在web上),并且服务器声明web URI可以/应该重定向到本机应用程序
请注意,还有其他默认的非webscheme
,如众所周知的mailto:<mail_address>
或tel:<number>
-工作方式相同:系统将查找声明可以打开此类URI的应用程序。这些不会由web浏览器处理,它们不是web协议
https://stackoverflow.com/questions/66168280
复制相似问题