/// <summary> /// Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView. /// </summary> /// <param name="activity"> The host activity. </param> /// <param name="custom_tabs_intent"> a CustomTabsIntent to be used if Custom Tabs is available. </param> /// <param name="uri"> the Uri to be opened. </param> /// <param name="fallback"> a CustomTabFallback to be used if Custom Tabs is not available. </param> public /*static*/ void LaunchUrlWithCustomTabsOrFallback ( Activity activity, CustomTabsIntent custom_tabs_intent, Uri uri, ICustomTabFallback fallback ) { string packageName = PackageManagerHelper.GetPackageNameToUse(activity, uri.ToString()); //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null) { if (fallback != null) { fallback.OpenUri(activity, uri); } } else { custom_tabs_intent.Intent.SetPackage(packageName); custom_tabs_intent.LaunchUrl(activity, uri); } return; }
/// <summary> /// Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView. /// </summary> /// <param name="activity"> The host activity. </param> /// <param name="customTabsIntent"> a CustomTabsIntent to be used if Custom Tabs is available. </param> /// <param name="uri"> the Uri to be opened. </param> /// <param name="fallback"> a CustomTabFallback to be used if Custom Tabs is not available. </param> public static void OpenCustomTab ( Activity activity, CustomTabsIntent customTabsIntent, Android.Net.Uri uri, ICustomTabFallback fallback ) { string packageName = Org.Chromium.CustomTabsClient.Shared.CustomTabsHelper.GetPackageNameToUse(activity); //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null) { if (fallback != null) { fallback.OpenUri(activity, uri); } } else { customTabsIntent.Intent.SetPackage(packageName); customTabsIntent.LaunchUrl(activity, uri); } }
public static void OpenCustomTab(Activity activity, CustomTabsIntent customTabsIntent, Uri uri, ICustomTabFallback fallback) { var packageName = CustomTabsHelper.GetPackageNameToUse(activity); //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null) { fallback?.OpenUri(activity, uri); } else { customTabsIntent.Intent.SetPackage(packageName); customTabsIntent.LaunchUrl(activity, uri); } }
/// <summary> /// Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView. /// </summary> /// <param name="activity"> The host activity. </param> /// <param name="custom_tabs_intent"> a CustomTabsIntent to be used if Custom Tabs is available. </param> /// <param name="uri"> the Uri to be opened. </param> /// <param name="fallback"> a CustomTabFallback to be used if Custom Tabs is not available. </param> public /*static*/ void LaunchUrlWithCustomTabsOrFallback ( Activity a, CustomTabsIntent custom_tabs_intent, Android.Net.Uri u, ICustomTabFallback fallback ) { uri = u; activity = a; string packageName = PackageManagerHelper.GetPackageNameToUse(activity, uri.ToString()); //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (packageName == null) { if (fallback != null) { fallback.OpenUri(activity, uri); } } else { custom_tabs_intent.Intent.SetPackage(packageName); // direct call to CustomtTasIntent.LaunchUrl was ported from java samples and refactored // seems like API changed // // custom_tabs_intent.LaunchUrl(activity, uri); custom_tabs_activit_manager = new CustomTabsActivityManager(activity); custom_tabs_activit_manager.CustomTabsServiceConnected += custom_tabs_activit_manager_CustomTabsServiceConnected; service_bound = custom_tabs_activit_manager.BindService(); if (service_bound == false) { // No Packages that support CustomTabs } } return; }
/// <summary> /// Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView. /// </summary> /// <param name="activity"> The host activity. </param> /// <param name="custom_tabs_intent"> a CustomTabsIntent to be used if Custom Tabs is available. </param> /// <param name="uri"> the Uri to be opened. </param> /// <param name="fallback"> a CustomTabFallback to be used if Custom Tabs is not available. </param> public /*static*/ void LaunchUrlWithCustomTabsOrFallback ( Activity a, CustomTabsIntent custom_tabs_intent, string package_name_for_custom_tabs, Android.Net.Uri u, ICustomTabFallback fallback ) { uri = u; activity = a; bool fallback_neccessary = false; //If we cant find a package name, it means theres no browser that supports //Chrome Custom Tabs installed. So, we fallback to the webview if (package_name_for_custom_tabs == null) { fallback_neccessary = true; } else { custom_tabs_activity_manager = new CustomTabsActivityManager(this.activity); custom_tabs_activity_manager.BindService(package_name_for_custom_tabs); //custom_tabs_intent.Intent.SetPackage(package_name_for_custom_tabs); custom_tabs_session = custom_tabs_activity_manager.Session; custom_tabs_intent_builder = new CustomTabsIntent.Builder(custom_tabs_session); // direct call to CustomtTasIntent.LaunchUrl was ported from java samples and refactored // seems like API changed //------------------------------------------------------------------------------ //custom_tabs_intent.LaunchUrl(activity, uri); //return; //------------------------------------------------------------------------------ custom_tabs_activity_manager = new CustomTabsActivityManager(activity); custom_tabs_intent = custom_tabs_intent_builder.Build(); CustomTabsHelper.AddKeepAliveExtra(activity, custom_tabs_intent.Intent); custom_tabs_intent.LaunchUrl(activity, uri); custom_tabs_activity_manager.CustomTabsServiceConnected += // custom_tabs_activit_manager_CustomTabsServiceConnected delegate { System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager.CustomTabsServiceConnected"); custom_tabs_activity_manager.LaunchUrl(uri.ToString()); System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager.LaunchUrl"); return; } ; System.Diagnostics.Debug.WriteLine($"CustomTabsActivityManager.BindService({package_name_for_custom_tabs})"); service_bound = custom_tabs_activity_manager.BindService(package_name_for_custom_tabs); //custom_tabs_activity_manager.LaunchUrl(uri.ToString()); //------------------------------------------------------------------------------ if (service_bound == false) { System.Diagnostics.Debug.WriteLine($"FALLBACK: No Packages that support CustomTabs"); // No Packages that support CustomTabs fallback_neccessary = true; } } if (fallback_neccessary == true && fallback != null) { fallback.OpenUri(activity, uri); } return; }