Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open a YouTube video link directly from an Android app?

I want to play a YouTube video on a click of a Button, but I am getting an action dialog window that I don't want to show. I want that the YouTube video link should open directly in the YouTube app on a Button click rather than showing this "choose action" window:

Enter image description here

How is it possible?

Code:

 playVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=bzSTpdcs-EI")));
        }
    });
like image 703
Kapil Rajput Avatar asked Oct 29 '25 17:10

Kapil Rajput


1 Answers

You can set the package name of the YouTube application:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=bzSTpdcs-EI"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.google.android.youtube");
startActivity(intent)
like image 177
Ravi Avatar answered Oct 31 '25 08:10

Ravi