我怎么能让我的应用只出现在意图选择器的特定url ?

时间:2022-01-20 15:06:12

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.

我正在开发一款应用程序,可以从某些网页中提取信息。这个想法是,当用户在浏览器中的特定url路径中并按下共享按钮时,我的应用程序将出现在接收端应用程序列表中。

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>

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:

但是,这将使我的应用程序出现在所有url的列表中,也包括那些它不需要做任何事情的列表。相反,我希望应用程序只出现在这些url的选择器中:

www.example.com/foo/bla.html

www.example.com/foo/bla.html

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

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

But not from these:

但不是从这些:

www.example.com

www.example.com

www.foobar.com

www.foobar.com

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.

等Ie。只有在特定主机上的特定路径内。还要注意,当用户单击符合条件的链接时,我不希望启动我的应用程序。只能从共享菜单中调用。

So my question is: How can I limit my app to show up in the intent choose only for certain urls?

所以我的问题是:我如何限制我的应用只在特定url上显示?

3 个解决方案

#1


4  

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.

向目标活动添加以下过滤器。1。主机站点名。2。您的站点http或https的scheme方案。3所示。应用程序应该显示的文件路径的路径。

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

#2


3  

How can I limit my app to show up in the intent choose only for certain urls?

我怎样才能限制我的应用只在特定的url中显示?

You can't. ACTION_SEND has no notion of "only from certain URLs", or "only from certain WhatsApp users", or "only from left-handed Alaskan pipe-welders".

你不能。ACTION_SEND没有“只从特定的url”,或者“只从特定的WhatsApp用户”,或者“只从阿拉斯加的左撇子管道焊工”的概念。

This is not significantly different than any other activity. An <intent-filter> only controls what the Intent is being delivered to. Nothing controls what the Intent is delivered from, with the exception of security-related items (permissions, whether or not the component is exported, etc.).

这与其他活动没有明显的不同。一个< Intent -filter>只控制意图被传递到什么地方。除了与安全相关的项目(不管组件是否导出等)之外,没有任何东西可以控制意图的传递。

So, with ACTION_VIEW, the URL is something being delivered to another activity ("I wish to view this URL"). This works because the URL is turned into the Uri of the Intent, and that can be filtered upon via <data> elements in the <intent-filter>.

因此,对于ACTION_VIEW, URL是传递给另一个活动的东西(“我想查看这个URL”)。这之所以有效,是因为URL被转换为意图的Uri,并且可以通过< Intent -filter>中的 元素进行过滤。

But ACTION_SEND doesn't have to have a URL, and even if there is one, it is merely payload in the form of an extra. It is not something that can be filtered upon.

但是ACTION_SEND不需要有URL,即使有URL,它也只是额外的有效负载。它不是可以过滤的东西。

Hence, what you want is not supported.

因此,您想要的是不受支持的。

#3


-1  

Use pathPrefix

使用pathPrefix

    <intent-filter>
         <data
            android:host="www.example.com"
            android:scheme="http"
            android:pathPrefix="/foo/"
            />
        <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>

#1


4  

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.

向目标活动添加以下过滤器。1。主机站点名。2。您的站点http或https的scheme方案。3所示。应用程序应该显示的文件路径的路径。

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

#2


3  

How can I limit my app to show up in the intent choose only for certain urls?

我怎样才能限制我的应用只在特定的url中显示?

You can't. ACTION_SEND has no notion of "only from certain URLs", or "only from certain WhatsApp users", or "only from left-handed Alaskan pipe-welders".

你不能。ACTION_SEND没有“只从特定的url”,或者“只从特定的WhatsApp用户”,或者“只从阿拉斯加的左撇子管道焊工”的概念。

This is not significantly different than any other activity. An <intent-filter> only controls what the Intent is being delivered to. Nothing controls what the Intent is delivered from, with the exception of security-related items (permissions, whether or not the component is exported, etc.).

这与其他活动没有明显的不同。一个< Intent -filter>只控制意图被传递到什么地方。除了与安全相关的项目(不管组件是否导出等)之外,没有任何东西可以控制意图的传递。

So, with ACTION_VIEW, the URL is something being delivered to another activity ("I wish to view this URL"). This works because the URL is turned into the Uri of the Intent, and that can be filtered upon via <data> elements in the <intent-filter>.

因此,对于ACTION_VIEW, URL是传递给另一个活动的东西(“我想查看这个URL”)。这之所以有效,是因为URL被转换为意图的Uri,并且可以通过< Intent -filter>中的 元素进行过滤。

But ACTION_SEND doesn't have to have a URL, and even if there is one, it is merely payload in the form of an extra. It is not something that can be filtered upon.

但是ACTION_SEND不需要有URL,即使有URL,它也只是额外的有效负载。它不是可以过滤的东西。

Hence, what you want is not supported.

因此,您想要的是不受支持的。

#3


-1  

Use pathPrefix

使用pathPrefix

    <intent-filter>
         <data
            android:host="www.example.com"
            android:scheme="http"
            android:pathPrefix="/foo/"
            />
        <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>