1

I would like to intercept an intent with a BroadcastReceiver, in the youtube app, when a video starts to play - I managed to read this from the logs:

Starting: Intent { cmp=com.google.android.youtube/.WatchActivity (has extras) } from pid 18710

I tried to add this to the manifest:

<intent-filter>
        <component android:name="com.google.android.youtube/.WatchActivity"/>

        </intent-filter>

But this didn't work.

What do you think?

Serge
  • 1,066
  • 2
  • 7
  • 24
Alex1987
  • 9,397
  • 14
  • 70
  • 92
  • What are you trying to accomplish? – adamp Apr 09 '11 at 19:56
  • I'm trying to get the download url of the video, and notify my app – Alex1987 Apr 09 '11 at 20:00
  • For what purpose? If you want your app to show up as an alternate way to open YouTube URLs you can do that with an intent filter on an activity. Or are you trying to do something else? – adamp Apr 09 '11 at 20:11
  • "If you want your app to show up as an alternate way to open YouTube URLs you can do that with an intent filter on an activity" - How exactly? Actually I'm writing an app that downloads youtube videos. Now I want it to recognize when a user begins to watch a video, and then ask him if he wants to download the video. Is this possible? – Alex1987 Apr 09 '11 at 20:22

2 Answers2

2

What do you think?

You cannot "intercept an intent with a BroadcastReceiver" when that Intent is being used to start an activity.

Also, there is no <component> element in an <intent-filter>.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
2

If you want to let your app respond to specifically formed HTTP URLs such as a youtube video URL, set up an intent filter that responds to ACTION_VIEW intents with a <data> element that defines the URL pattern you want to match.

Android uses ACTION_SEND intents to share things like links or photos. You can also have your app respond to shared links. Setting this up will be almost the same as setting up an intent filter for ACTION_VIEW intents.

See the "data test" section of the Android documentation on intent filters here for more detail.

One way or another, there is not a way to "spy" on another 3rd party app silently unless that app publishes the information for other apps to read. Both of the approaches above will involve the user specifically telling the system to use your app to handle the URL in question. The first way, the user will get to pick which app to use to view the content in the first place. The second way, the user will have to press a share button in the original app and choose to share the link to your app.

All of that said, since you mentioned what you're trying to do above, please respect the copyrights of others.

adamp
  • 28,862
  • 9
  • 81
  • 69
  • An example of doing this: http://stackoverflow.com/questions/1609573/intercepting-links-from-the-browser-to-open-my-android-app/1609662#1609662 – LouieGeetoo Sep 14 '11 at 00:40