void BindCustomTabsService() { if (mClient != null) { return; } if (TextUtils.IsEmpty(mPackageNameToBind)) { mPackageNameToBind = CustomTabsHelper.GetPackageNameToUse(this); if (mPackageNameToBind == null) { return; } } mConnection = new ServiceConnection(this); bool ok = CustomTabsClient.BindCustomTabsService(this, mPackageNameToBind, mConnection); if (ok) { mConnectButton.Enabled = false; } else { mConnection = null; } }
public void BindCustomTabsService(Activity activity) { if (mClient != null) { return; } var packageName = CustomTabsHelper.GetPackageNameToUse(activity); if (packageName == null) { return; } mConnection = new ServiceConnection(this); CustomTabsClient.BindCustomTabsService(activity, packageName, mConnection); }
public void OnClick(View view) { string url = mEditText.Text; bool success; switch (view.Id) { case Resource.Id.connect_button: BindCustomTabsService(); break; case Resource.Id.warmup_button: success = false; if (mClient != null) { success = mClient.Warmup(0); } mWarmupButton.Enabled &= success; break; case Resource.Id.may_launch_button: CustomTabsSession session = GetSession(); success = false; if (mClient != null) { success = session.MayLaunchUrl(Uri.Parse(url), null, null); } mMayLaunchButton.Enabled &= success; break; case Resource.Id.launch_button: var builder = new CustomTabsIntent.Builder(GetSession()); builder.SetToolbarColor(Color.ParseColor(TOOLBAR_COLOR)).SetShowTitle(true); PrepareMenuItems(builder); PrepareActionButton(builder); PrepareBottombar(builder); builder.SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left); builder.SetExitAnimations(this, Resource.Animation.slide_in_left, Resource.Animation.slide_out_right); builder.SetCloseButtonIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_arrow_back)); CustomTabsIntent customTabsIntent = builder.Build(); CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent); customTabsIntent.LaunchUrl(this, Uri.Parse(url)); break; } }
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); } }
public void OnClick(View view) { Uri uri = Uri.Parse(mUrlEditText.Text); switch (view.Id) { case Resource.Id.button_may_launch_url: customTabActivityHelper.MayLaunchUrl(uri, null, null); break; case Resource.Id.start_custom_tab: CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(customTabActivityHelper.GetSession()).Build(); CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent); CustomTabActivityHelper.OpenCustomTab(this, customTabsIntent, uri, new WebviewFallback()); break; default: throw new Exception("Unkown View Clicked"); } }