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 butto
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>
Use 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>
How can I limit my app to show up in the intent choose only for certain urls?
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".
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.).
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>
.
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.
Hence, what you want is not supported.