我正在开发一款可以从某些网页中提取信息的应用程序。这个想法是,当用户在浏览器中的特定 url 路径内并按下共享按钮时,我的应用程序将显示在接收方应用程序列表中。
我可以通过将此添加到 list 中轻松地做到这一点:
<intent-filter android:label="@string/app_name" >
<action android:name="android.intent.action.SEND" />
<data android:mimeType="text/plain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
但是,这将使我的应用程序出现在所有 url 的列表中,也包括所有与它无关的 url。相反,我希望该应用仅通过这些网址出现在选择器中:
www.example.com/foo/bla.html
www.example.com/foo/bar/blabla.html
但不是来自这些:
www.example.com
www.foobar.com
等IE。仅来自特定主机上的特定路径。另请注意,我不希望在用户单击符合条件的链接时启动我的应用程序。它只能从共享菜单中调用。
所以我的问题是:如何限制我的应用程序只显示在特定 url 的 Intent 选择中?
最佳答案
将以下过滤器添加到目标 Activity .. 1. 托管您的网站名称。 2. scheme 您网站的方案 http 或 https。 3. path 您的应用应显示的文件路径。
<intent-filter>
<data
android:host="www.example.com"
android:scheme="http"
android:path="/foo/bla.html"
/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" >
</category>
<category android:name="android.intent.category.BROWSABLE" >
</category>
</intent-filter>
关于android - 如何让我的应用仅针对特定网址出现在 Intent 选择器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22758089/