如何让我的应用仅在某些网址中出现在意图选择器中? [英] How can I have my app appear in the intent chooser only for certain urls?

查看:67
本文介绍了如何让我的应用仅在某些网址中出现在意图选择器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个可以从某些网页提取信息的应用程序.这样的想法是,当用户位于浏览器中的特定url路径中并按共享"按钮时,我的应用程序将显示在接收器应用程序列表中.

I am developing an app that can extract information from certain web pages. The idea is that when the user is within a specific url path in the browser and press the share button, my app will show up in the list of receiver apps.

我可以通过将其添加到清单中来轻松做到这一点:

I can do that easily by adding this to the manifest:

<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.相反,我希望应用程序仅从以下网址出现在选择器中:

However, this will make my app appear on the list on all urls, also all those where it will have nothing to do. Instead I would like the app appear in the chooser only from these urls:

www.example.com/foo/bla.html

www.example.com/foo/bar/blabla.html

但不是这些:

www.example.com

www.foobar.com

等IE.仅来自特定主机上的特定路径.还要注意,当用户单击符合条件的链接时,我不希望启动我的应用程序.只能从共享菜单中调用它.

etc. Ie. only from within a certain path on a certain host. Also note that I do not want my app to be launched when the user clicks on links matching the criteria. It should only be invoked from the share menu.

所以我的问题是:如何限制我的应用程序仅显示在某些网址的意图中显示?

推荐答案

将以下过滤器添加到目标活动.. 1. 托管您的网站名称. 2.您的网站http或https的方案方案. 3. 路径为您的应用程序应显示的文件路径.

Add the following filter to the destination Activity .. 1. host your site name. 2. scheme scheme of your site http or https. 3. path for the file path your app should display.

<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>

这篇关于如何让我的应用仅在某些网址中出现在意图选择器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆