android youtube: share a youtube video TO my app?

12,428

Solution 1

This worked for me. Add this intent filter to your manifest file to make your application appear in the share list of the youtube application.

<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>

Then to retrieve it in your activity, use this :

Bundle extras = getIntent().getExtras();
 String value1 = extras.getString(Intent.EXTRA_TEXT);

Here you are!

Solution 2

I played around a bit and ended with this solution:

<intent-filter android:label="My YT Handler">
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:host="youtu.be" android:mimeType="text/*" />
</intent-filter>
Share:
12,428
Carsten Drösser
Author by

Carsten Drösser

Updated on June 03, 2022

Comments

  • Carsten Drösser
    Carsten Drösser almost 2 years

    The built in YouTube App for tablets has a sharing-option. For example: I watch a video in the YouTube app and click the button to share. Bluetooth, Googlemail, and Dropbox appear for me. I wonder how i can list my app there? Which intent-filter has my app to have? How do i get the video url then? Any idea? Thanks.

  • PedroD
    PedroD almost 9 years
    Why the hell does this one work, but this one (stackoverflow.com/questions/525063/…) doesn't?
  • PedroD
    PedroD almost 9 years
    It works but android:scheme is missing from <data>, what should we put there?
  • arc
    arc about 8 years
    You may add android:scheme="http" to <data with newer versions of android. @PedroD
  • Samuel Bushi
    Samuel Bushi over 6 years
    This answer doesn't work exclusively for YouTube, you can share any text to your Activity, if you use this intent-filter. I thought that this was because of the missing scheme but adding a https scheme removes myApp from the IntentChooser altogether.