How to open a youtube link from your app

You need to place a video from youtube in the app. But when you click on it, the user must go to the official youtube app(or to have a choice of what to open). That is, so that it is not played in the app itself, but is thrown to the browser or to the Youtube app. How to implement it?

Author: pavlofff, 2017-04-07

1 answers

The function opens the video by the specified id in the youtube app, if the app is not found, then in the browser.

public void watchYoutubeVideo(String id){
    Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id));
    Intent webIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://www.youtube.com/watch?v=" + id));
    try {
        startActivity(appIntent);
    } catch (ActivityNotFoundException ex) {
        startActivity(webIntent);
    }
}

Taken hence

 1
Author: Leonid, 2017-05-23 12:39:01