-1

In android when I am sending an intent with URL for example "google.com" the system will provide me the list of allowed browsers. How I can make it open that link in particular browser without choosing?

Bo Z
  • 2,359
  • 1
  • 13
  • 31
  • You need to create an explicit Intent, rather then implicit. I believe that this answer will be useful https://stackoverflow.com/a/27780129/10228281. Although the question is about Chrome, you can adapt it to the browser you want. – Vassil Angelov Feb 18 '21 at 16:28
  • Keep in mind that in most cases, you shouldn't want to do this. It's a better experience for users if they can use their preferred browser. – PPartisan Feb 19 '21 at 14:38

2 Answers2

2

You can open any url using specific browser by using its package but if browser not found in some device then have to handle exception. Here,I am using chrome browser specifically to open this https://www.google.com

 Intent i=new Intent(ACTION_VIEW, Uri.parse("https://www.google.com"));
        i.setPackage("com.android.chrome");
        startActivity(i);

Note - I assume Chrome browser is available in device.

Tanmay Ranjan
  • 318
  • 2
  • 8
-1

You can use custom tab builder, something like this in your onClick function

val builder = CustomTabsIntent.Builder()
            builder.setToolbarColor(ContextCompat.getColor(requireContext(),R.color.red))
            builder.setShowTitle(true)
            builder.build().launchUrl(requireContext(), Uri.parse(url))
          }
Alpha 1
  • 4,118
  • 2
  • 17
  • 23
Greeshma
  • 312
  • 1
  • 10