i have youtube button which will open a particular *channel* for that i want it to open in youtube *application* in order to access a channel from my application.
Intent intent = new Intent(Intent.ACTION_VIEW , Uri.parse("https://www.youtube.com/channel/UCRmoG8dTnv0B7y9uoocikLw"));
context.startActivity(intent);
But it is opening in browser.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.youtube.com/"));
intent.setPackage("com.google.android.youtube");
PackageManager manager = getPackageManager();
List<ResolveInfo> info = manager.queryIntentActivities(intent, 0);
if (info.size() > 0) {
startActivity(intent);
} else {
//No Application can handle your intent
}
This is how u can achieve.. providing only "https://www.youtube.com/" will directly land you into home feed. While one can definitely customize url to redirect to particular channel or video.
You should explicitly send it to youtube. You can do this by specifing the package:
intent.setComponent(new ComponentName("com.google.android.youtube","com.google.android.youtube.PlayerActivity"));
Also note that you should also check if youtube is installed!
Intent intent = new Intent(
Intent.ACTION_VIEW ,
Uri.parse("https://www.youtube.com/channel/UCRmoG8dTnv0B7y9uoocikLw"));
intent.setComponent(new ComponentName("com.google.android.youtube","com.google.android.youtube.PlayerActivity"));
PackageManager manager = context.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
if (infos.size() > 0) {
context.startActivity(intent);
}else{
//No Application can handle your intent
}
I found this to be a simple way to do this (assumes you already checked that YouTube is installed):
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.youtube.com/**YOURCHANNEL**"));
intent.setPackage("com.google.android.youtube");
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With