Rahul Matte
Rahul Matte

Reputation: 1181

How to open the youtube app using Intent

How can I launch youtube app using intent

         Intent intent = new  Intent(Intent.ACTION_VIEW);

         intent.setPackage("com.google.android.youtube");    
         intent.setData(Uri.parse("https://www.youtube.com/watch?v=3TKSW-VgVyM"));

         startActivity(intent);

The above code plays the video in youtube, but I want to open only youtube app, How Can I achieve this? Thanks in advance

Upvotes: 3

Views: 8714

Answers (2)

Ben Magill
Ben Magill

Reputation: 48

This is the code needed for launching the Youtube app. Using this inside an onclicklistener is probably best.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube");
startActivity( launchIntent );

Upvotes: 1

Budius
Budius

Reputation: 39836

you can open it using the package name com.google.android.youtube

start application knowing package name

Intent.getLaunchIntentForPackage("com.google.android.youtube");

Upvotes: 1

Related Questions