code: @Nullable
      static String getBestBrowserPackage(@NonNull Context context) {
          PackageManager pm = context.getPackageManager();
          Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
          ResolveInfo webHandler = pm.resolveActivity(browserIntent,
                  Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PackageManager.MATCH_ALL : PackageManager.MATCH_DEFAULT_ONLY);
          String defaultBrowser = null;
          if (webHandler != null) {
              defaultBrowser = webHandler.activityInfo.packageName;
          }
  
          List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(browserIntent, 0);
          List<String> customTabsBrowsers = new ArrayList<>();
          for (ResolveInfo info : resolvedActivityList) {
              Intent serviceIntent = new Intent();
              serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
              serviceIntent.setPackage(info.activityInfo.packageName);
              if (pm.resolveService(serviceIntent, 0) != null) {
                  customTabsBrowsers.add(info.activityInfo.packageName);
              }
          }
          if (customTabsBrowsers.contains(defaultBrowser)) {
              return defaultBrowser;
          } else if (customTabsBrowsers.contains(CHROME_STABLE)) {
              return CHROME_STABLE;
          } else if (customTabsBrowsers.contains(CHROME_SYSTEM)) {
              return CHROME_SYSTEM;
          } else if (customTabsBrowsers.contains(CHROME_BETA)) {
              return CHROME_BETA;
          } else if (customTabsBrowsers.contains(CHROME_DEV)) {
              return CHROME_DEV;
          } else if (!customTabsBrowsers.isEmpty()) {
              return customTabsBrowsers.get(0);
          } else {
              return null;
          }
      }
docs: Query the OS for a Custom Tab compatible Browser application.
  It will pick the default browser first if is Custom Tab compatible, then any Chrome browser or the first Custom Tab compatible browser.
  
  @param context a valid Context
  @return the recommended Browser application package name, compatible with Custom Tabs. Null if no compatible browser is found.