[Android] How to Play Videos in Official YouTube App with Explicit Intent
In Android app development, I found that the code for playing videos in the official YouTube app with explicit Intent was buggy, so I researched working code and made notes.
Non-working Code
final videoId = "kCNpOe5S1B4";
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://m.youtube.com/watch?v=" + videoId));
intent.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
Code that Successfully Plays YouTube Videos
final videoId = "kCNpOe5S1B4";
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("vnd.youtube:" + videoId));
intent.putExtra("VIDEO_ID", videoId);
That’s all from the Gemba for playing videos in the official YouTube app with explicit Intent on Android.