问题
Im trying to receive an intent from the Youtube App. I.e. when i press share it should list my app on the apps ready to accept this intent. But none of these works
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
<data
android:host="*"
android:scheme="youtube" />
<data
android:host="*"
android:scheme="vnd.youtube" />
</intent-filter>
or with action VIEW
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
<data
android:host="*"
android:scheme="youtube" />
<data
android:host="*"
android:scheme="vnd.youtube" />
</intent-filter>
Any idea about how to get the intent as well once sent? Thanks
回答1:
The YouTube app sends text/plain
data, so register your activity as a receiver of that mimetype:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
回答2:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.youtube.com"
android:mimeType="text/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="m.youtube.com"
android:mimeType="text/plain" />
</intent-filter>
回答3:
You seem to be quite confused. The intents you are using seem to be the intents that an app like the YouTube app itself would use to open videos. What you want is to share a YouTube video, i.e. a link, so as the other answers mention, you should declare a text/plain
intent-filter.
However, this intent-filter will capture all text/plain
content and not only the ones that come from YouTube. See: Intent-filter: How to accept only "text/plain" intents containing the word "spaghetti"
来源:https://stackoverflow.com/questions/17256003/youtube-intent-filter-scheme