我在某些应用程序中看到,当您单击链接时,它会询问您是否要在应用程序中打开它。我在许多帖子中看到您可以执行此操作
<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="www.ex-ample.com" android:scheme="http" />
</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:mimeType="vnd.android.cursor.item/vnd.example.crag" />
<data android:host="www.ex-ample.com" android:scheme="http" />
</intent-filter>
它似乎不起作用,我单击了转到 www.ex-ample.com/test/123 的文本中的链接,它只是在浏览器中打开。
我真的很想知道两件事:
- 你能同时使用 mineType 和 host/scheme 属性吗
- 你能看出这还有什么问题吗?
最佳答案
can you use a mineType and a host/scheme attribute together
是的,至少根据 the docs on <data>
.
can you see anything else wrong with this?
如果http://www.ex-ample.com/test/123不返回 MIME 类型的文档 vnd.android.cursor.item/vnd.example.crag
在 HTTP HEAD 请求中,您的 <intent-filter>
将不匹配。
关于Android Intent-filter mimetype 和主机/方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11075179/