I would like to intercept an intent with a BroadcastReceiver, in the youtube app, when a video starts to play - I manag开发者_高级运维ed 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?
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.
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>
.
精彩评论