Search code examples
android-activityyoutube-apiandroid-developer-api

How to open Youtube app from another app after clicking a button with a query searched in youtube?


What should i define in my activity i.e Action, ActivityClass, ActivityPackage, ExtraKey and ExtraValue to define an intent in app to open Youtube app in and android phone to open with "ExtraValue" searched in youtube? I am trying the following combination but getting Error 601.

Action: android.intent.action.SEARCH
ActivityClass: com.google.android.youtube.WatchActivity
ActivityPackage: com.google.android.youtube
DataType: 
DataUri: 
ExtraKey: query
ExtraValue: app Inventor activity starter
ResultName: 

Solution

  • use this on your project: https://developers.google.com/youtube/android/player/downloads/

    include this code in your onclick method:

    Intent intent = YouTubeStandalonePlayer.createVideoIntent(getActivity(), api_key, video_id);
    startActivity(intent);
    

    api_key is the Google Console APIs developer key. video_id is the code after v=, for example:fYWZNN4bbz8 in "https://www.youtube.com/watch?v=fYWZNN4bbz8"

    :)