예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <summary>
        /// Binds the Activity to the Custom Tabs Service. </summary>
        /// <param name="activity"> the activity to be binded to the service. </param>
        public virtual void BindCustomTabsService(Activity activity)
        {
            if (custom_tabs_client != null)
            {
                return;
            }

            string packageName = PackageManagerHelper.GetPackageNameToUse(activity, this.UriTest);

            if (packageName == null)
            {
                Toast.MakeText
                (
                    activity,
                    "No packages supporting CustomTabs found!",
                    ToastLength.Short
                ).Show();

                return;
            }

            custom_tabs_service_connection = new ServiceConnection(this);
            CustomTabsClient.BindCustomTabsService(activity, packageName, custom_tabs_service_connection);

            return;
        }