3

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

Rahul Matte
  • 1,151
  • 2
  • 23
  • 54

2 Answers2

1

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

start application knowing package name

Intent.getLaunchIntentForPackage("com.google.android.youtube");
Community
  • 1
  • 1
Budius
  • 39,391
  • 16
  • 102
  • 144
1

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 );
Ben Magill
  • 38
  • 3
  • 8