3

I want user to enter list of url's of video (youtube links). So I thought of using customtabs with adding a new menuItem in the tabs.

If youtube app is disabled or not installed in user android device, custom tabs is opened with my desired youtube url.

But then youtube app is installed and is enable, then when I launchUrl in my custom tabs, youtube app is launched, which I don't want. I always want to launch youtube url in custom tabs. How to achieve that? Any suggestions?

Vishwesh Jainkuniya
  • 2,821
  • 3
  • 18
  • 35

2 Answers2

2

In case of Chrome Browser, to achieve this, please set the CustomTabsIntent with the Package of Chrome before launching the youtube url in chrome custom tabs.

intentCustomTabs.intent.setPackage("com.android.chrome");

For details implementation please check from here, hopefully it will help.

mdrafiqulrabin
  • 1,657
  • 5
  • 28
  • 38
  • 5
    Beware that other browsers, such as Samsung Internet Browser and Firefox have implemented or are implementing support for Custom Tabs. By setting a hardcoded package to `com.android.chrome`, users who have set their preferred browser as something other than Chrome won't have their preferences honored, and your application may break on systems that don't have Chrome installed. The best practices explain how to create a code that works with other browsers: https://developer.chrome.com/multidevice/android/customtabs#bestpractices – andreban Feb 28 '17 at 19:45
0

You can use this to get the default custom tab browser package name.

val customTabPackageName = CustomTabsClient.getPackageName(requireContext(), null)

Then you can set the intent package to that name.

customTabIntent.intent.setPackage(customTabPackageName)

This will stop apps like youtube from hijacking your custom tab

John Oberhauser
  • 396
  • 1
  • 3
  • 12