Search code examples
androidandroid-intentyoutube

Force video to open in Youtube app on Android


I have a mobile website that links to a youtube video. On Android, clicking on this link brings up a dialog asking the user to "Complete action using" their browser or the Youtube app.

Is there a way to bypass this screen and just play the video in the Youtube app? (For example with a youtube:// URL.)

Thanks!


Solution

  • Here's how you can do that:

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
    startActivity(intent);
    

    The id is the identifier after the questionmark in the url. For example: youtube.com/watch?v=ID

    Another way is:

    Intent videoIntent = new Intent(Intent.ACTION_VIEW);
    videoIntent.setData(url);
    videoIntent.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
    startActivity(videoIntent);
    

    ......