Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch Android share intents limited to specific URLs using intent-filter?

I can hook my app into the "Share page" feature using the following intent-filter:

<intent-filter>
  <action android:name="android.intent.action.SEND" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="text/plain" />

But I would like to go a little further and limit the filter to intents with specific URLs in them, for example URL of a YouTube video. I tried something like this but it doesn't work:

<intent-filter>
  <action android:name="android.intent.action.SEND" />
  <category android:name="android.intent.category.DEFAULT" />
  <data
    android:mimeType="text/plain"
    android:scheme="http"
    android:host="m.youtube.com"
  />

Any suggestions?

like image 833
Marek Stój Avatar asked Feb 13 '11 20:02

Marek Stój


People also ask

Can an activity have multiple intent filters?

However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another. An <intent-filter> element in the manifest file lists actions as <action> subelements. For example: <intent-filter . . . >

What is the use of intent createChooser () method?

createChooser(intent, title); // Try to invoke the intent. // Define what your app should do if no activity can handle the intent. This displays a dialog with a list of apps that respond to the intent passed to the createChooser() method and uses the supplied text as the dialog title.

What is the use of intent filter tag in Android?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

How does intent filter work?

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.


1 Answers

But I would like to go a little further and limit the filter to intents with specific URLs in them, for example URL of a YouTube video.

What you are asking for makes no sense to me as written.

Perhaps you really mean:

But I would like to go a little further and limit the filter to ACTION_SEND requests where the body extra contains a specific URL

In which case, that is impossible, sorry.

Or, perhaps you really mean:

But I would like to go a little further and limit the filter to ACTION_SEND requests issued from random pieces of software that happen to be thinking of a specific URL at the time user happened to press "share", such as sharing the current YouTube video being played in the YouTube app

In which case, that is impossible, sorry.

If neither of those guesses really hit what you are asking for, please consider editing your question.

like image 125
CommonsWare Avatar answered Oct 01 '22 02:10

CommonsWare