Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have my app appear in the intent chooser only for certain urls?

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>

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

But not from these:

www.example.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.

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

like image 947
marlar Avatar asked Mar 31 '14 09:03

marlar


1 Answers

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>
like image 152
Dharani Kumar Avatar answered Sep 30 '22 06:09

Dharani Kumar