static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) { var nativeUri = AndroidUri.Parse(uri.AbsoluteUri); switch (options.LaunchMode) { case BrowserLaunchMode.SystemPreferred: var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(true); if (options.PreferredToolbarColor.HasValue) { tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.Value.ToInt()); } if (options.TitleMode != BrowserTitleMode.Default) { tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show); } var tabsIntent = tabsBuilder.Build(); var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; #if __ANDROID_24__ if (Platform.HasApiLevelN) { flags |= ActivityFlags.LaunchAdjacent; } #endif tabsIntent.Intent.SetFlags(flags); #if __ANDROID_25__ tabsIntent.LaunchUrl(Platform.AppContext, nativeUri); #else tabsIntent.LaunchUrl(Platform.GetCurrentActivity(true), nativeUri); #endif break; case BrowserLaunchMode.External: var intent = new Intent(Intent.ActionView, nativeUri); flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; #if __ANDROID_24__ if (Platform.HasApiLevelN) { flags |= ActivityFlags.LaunchAdjacent; } #endif intent.SetFlags(flags); if (!Platform.IsIntentSupported(intent)) { throw new FeatureNotSupportedException(); } Platform.AppContext.StartActivity(intent); break; } return(Task.FromResult(true)); }
static void LaunchChromeTabs(BrowserLaunchOptions options, AndroidUri?nativeUri) { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(true); #pragma warning disable CS0618 // Type or member is obsolete if (options.PreferredToolbarColor != null) { tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.ToInt()); } #pragma warning restore CS0618 // Type or member is obsolete if (options.TitleMode != BrowserTitleMode.Default) { tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show); } var tabsIntent = tabsBuilder.Build(); ActivityFlags?tabsFlags = null; Context?context = ActivityStateManager.Default.GetCurrentActivity(false); if (context == null) { context = Application.Context; // If using ApplicationContext we need to set ClearTop/NewTask (See #225) tabsFlags = ActivityFlags.ClearTop | ActivityFlags.NewTask; } #if __ANDROID_24__ if (OperatingSystem.IsAndroidVersionAtLeast(24)) { if (options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) { if (tabsFlags.HasValue) { tabsFlags |= ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; } else { tabsFlags = ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; } } } #endif // Check if there's flags specified to use if (tabsFlags.HasValue) { tabsIntent.Intent.SetFlags(tabsFlags.Value); } if (nativeUri != null) { tabsIntent.LaunchUrl(context, nativeUri); } }
void Initialize() { var webViewClient = new ARWebViewClient((e) => { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(false); var intent = tabsBuilder.Build(); intent.LaunchUrl(this.Context, Android.Net.Uri.Parse(e.Url)); return(true); }); SetWebViewClient(webViewClient); _chromeClient = new ARWebChromeClient(); _chromeClient.ShowCustomView = (arg1, arg2) => { this.Visibility = ViewStates.Gone; OnShowCustomView?.Invoke(arg1, arg2); }; _chromeClient.HideCustomView = () => { this.Visibility = ViewStates.Visible; OnHideCustomView?.Invoke(); }; SetWebChromeClient(_chromeClient); Settings.JavaScriptEnabled = true; }
public static Task OpenAsync(Uri uri, BrowserLaunchType launchType) { if (uri == null) { throw new ArgumentNullException(nameof(uri), "Uri cannot be null."); } var nativeUri = AndroidUri.Parse(uri.OriginalString); switch (launchType) { case BrowserLaunchType.SystemPreferred: var tabsBuilder = new CustomTabsIntent.Builder(); var tabsIntent = tabsBuilder.Build(); tabsBuilder.SetShowTitle(true); tabsIntent.LaunchUrl(Platform.CurrentContext, nativeUri); break; case BrowserLaunchType.External: var intent = new Intent(Intent.ActionView, nativeUri); intent.SetFlags(ActivityFlags.ClearTop); intent.SetFlags(ActivityFlags.NewTask); if (!Platform.IsIntentSupported(intent)) { throw new FeatureNotSupportedException(); } Platform.CurrentContext.StartActivity(intent); break; } return(Task.CompletedTask); }
static Task PlatformOpenAsync(Uri uri, BrowserLaunchMode launchMode) { var nativeUri = AndroidUri.Parse(uri.AbsoluteUri); switch (launchMode) { case BrowserLaunchMode.SystemPreferred: var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(true); var tabsIntent = tabsBuilder.Build(); tabsIntent.Intent.SetFlags(ActivityFlags.ClearTop); tabsIntent.Intent.SetFlags(ActivityFlags.NewTask); tabsIntent.LaunchUrl(Platform.AppContext, nativeUri); break; case BrowserLaunchMode.External: var intent = new Intent(Intent.ActionView, nativeUri); intent.SetFlags(ActivityFlags.ClearTop); intent.SetFlags(ActivityFlags.NewTask); if (!Platform.IsIntentSupported(intent)) { throw new FeatureNotSupportedException(); } Platform.AppContext.StartActivity(intent); break; } return(Task.CompletedTask); }
void OpenCustomTab() { string url = mUrlEditText.Text; int color = GetColor(mCustomTabColorEditText); int secondaryColor = GetColor(mCustomTabSecondaryColorEditText); CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder(); intentBuilder.SetToolbarColor(color); intentBuilder.SetSecondaryToolbarColor(secondaryColor); if (mShowActionButtonCheckbox.Checked) { //Generally you do not want to decode bitmaps in the UI thread. Decoding it in the //UI thread to keep the example short. string actionLabel = GetString(Resource.String.label_action); Bitmap icon = BitmapFactory.DecodeResource(Resources, Android.Resource.Drawable.IcMenuShare); PendingIntent pendingIntent = CreatePendingIntent(ActionBroadcastReceiver.ACTION_ACTION_BUTTON); intentBuilder.SetActionButton(icon, actionLabel, pendingIntent); } if (mAddMenusCheckbox.Checked) { string menuItemTitle = GetString(Resource.String.menu_item_title); PendingIntent menuItemPendingIntent = CreatePendingIntent(ActionBroadcastReceiver.ACTION_MENU_ITEM); intentBuilder.AddMenuItem(menuItemTitle, menuItemPendingIntent); } if (mAddDefaultShareCheckbox.Checked) { intentBuilder.AddDefaultShareMenuItem(); } if (mToolbarItemCheckbox.Checked) { //Generally you do not want to decode bitmaps in the UI thread. Decoding it in the //UI thread to keep the example short. string actionLabel = GetString(Resource.String.label_action); Bitmap icon = BitmapFactory.DecodeResource(Resources, Android.Resource.Drawable.IcMenuShare); PendingIntent pendingIntent = CreatePendingIntent(ActionBroadcastReceiver.ACTION_TOOLBAR); intentBuilder.AddToolbarItem(TOOLBAR_ITEM_ID, icon, actionLabel, pendingIntent); } intentBuilder.SetShowTitle(mShowTitleCheckBox.Checked); if (mAutoHideAppBarCheckbox.Checked) { intentBuilder.EnableUrlBarHiding(); } if (mCustomBackButtonCheckBox.Checked) { intentBuilder.SetCloseButtonIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_arrow_back)); } intentBuilder.SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left); intentBuilder.SetExitAnimations(this, Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight); CustomTabActivityHelper.OpenCustomTab( this, intentBuilder.Build(), Uri.Parse(url), new WebviewFallback()); }
void OpenChromeCustomTabs(string url) { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(true); var intent = tabsBuilder.Build(); intent.LaunchUrl(CurrentActivity, Android.Net.Uri.Parse(url)); }
void IUrlHandler.LaunchBrowser(Uri uri) { var builder = new CustomTabsIntent.Builder(); builder.SetShowTitle(true); builder.SetUrlBarHidingEnabled(true); var customTabs = builder.Build(); customTabs.LaunchUrl(this, uri); }
public Task OpenBrowser(string url) { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(true); tabsBuilder.SetToolbarColor(ColorConstants.BrowserNavigationBarBackgroundColor.ToAndroid()); tabsBuilder.SetSecondaryToolbarColor(ColorConstants.BrowserNavigationBarTextColor.ToAndroid()); var intent = tabsBuilder.Build(); intent.LaunchUrl(CurrentContext, Android.Net.Uri.Parse(url)); return(Task.CompletedTask); }
/// <summary> /// Open a browser to a specific url /// </summary> /// <param name="url">Url to open</param> /// <param name="options">Platform specific options</param> /// <returns>True if the operation was successful, false otherwise</returns> public Task <bool> OpenBrowser(string url, BrowserOptions options = null) { try { options = options switch { null => new BrowserOptions(), _ => options }; switch (CrossCurrentActivity.Current.Activity) { case null: { var intent = new Intent(Intent.ActionView); intent.SetData(Android.Net.Uri.Parse(url)); intent.SetFlags(ActivityFlags.ClearTop); intent.SetFlags(ActivityFlags.NewTask); Application.Context.StartActivity(intent); break; } default: { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(options?.ChromeShowTitle ?? false); //var toolBarColor = options?.ChromeToolbarColor; //if (toolbarColor != null) // tabsBuilder.SetToolbarColor(toolbarColor.ToNativeColor()); var intent = tabsBuilder.Build(); intent.LaunchUrl(CrossCurrentActivity.Current.Activity, Android.Net.Uri.Parse(url)); break; } } return(Task.FromResult(true)); } catch (Exception ex) { Console.WriteLine("Unable to open browser: " + ex.Message); return(Task.FromResult(false)); } }
public Task <bool> OpenBrowser(string url, BrowserOptions options = null) { try { if (options == null) { options = new BrowserOptions(); } if (Platform.CurrentActivity == null) { var intent = new Intent(Intent.ActionView); intent.SetData(global::Android.Net.Uri.Parse(url)); intent.SetFlags(ActivityFlags.ClearTop); intent.SetFlags(ActivityFlags.NewTask); Platform.CurrentContext.StartActivity(intent); } else { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(options?.ChromeShowTitle ?? false); var toolbarColor = options?.ChromeToolbarColor; if (toolbarColor != null) { tabsBuilder.SetToolbarColor(toolbarColor.ToNativeColor()); } var intent = tabsBuilder.Build(); intent.LaunchUrl(Platform.CurrentActivity, global::Android.Net.Uri.Parse(url)); } return(Task.FromResult(true)); } catch (Exception ex) { Console.WriteLine("Unable to open browser: " + ex.Message); return(Task.FromResult(false)); } }
/// <summary> /// Open a browser to a specific url /// </summary> /// <param name="url">Url to open</param> /// <param name="options">Platform specific options</param> /// <returns>awaitable Task</returns> public async Task OpenBrowser(string url, BrowserOptions options = null) { try { if (options == null) { options = new BrowserOptions(); } if (CrossCurrentActivity.Current.Activity == null) { var intent = new Intent(Intent.ActionView); intent.SetData(Android.Net.Uri.Parse(url)); intent.SetFlags(ActivityFlags.ClearTop); intent.SetFlags(ActivityFlags.NewTask); Android.App.Application.Context.StartActivity(intent); } else { var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(options?.ChromeShowTitle ?? false); var toolbarColor = options?.ChromeToolbarColor; if (toolbarColor != null) { tabsBuilder.SetToolbarColor(Android.Graphics.Color.Argb(toolbarColor.A, toolbarColor.R, toolbarColor.G, toolbarColor.B)); } var intent = tabsBuilder.Build(); intent.LaunchUrl(CrossCurrentActivity.Current.Activity, Android.Net.Uri.Parse(url)); } } catch (Exception ex) { Console.WriteLine("Unable to open browser: " + ex.Message); } }
static Task <bool> PlatformOpenAsync(Uri uri, BrowserLaunchOptions options) { var nativeUri = AndroidUri.Parse(uri.AbsoluteUri); switch (options.LaunchMode) { case BrowserLaunchMode.SystemPreferred: var tabsBuilder = new CustomTabsIntent.Builder(); tabsBuilder.SetShowTitle(true); if (options.PreferredToolbarColor.HasValue) #pragma warning disable CS0618 // Type or member is obsolete { tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.Value.ToInt()); } #pragma warning restore CS0618 // Type or member is obsolete if (options.TitleMode != BrowserTitleMode.Default) { tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show); } var tabsIntent = tabsBuilder.Build(); ActivityFlags?tabsFlags = null; Context context = Platform.GetCurrentActivity(false); if (context == null) { context = Platform.AppContext; // If using ApplicationContext we need to set ClearTop/NewTask (See #225) tabsFlags = ActivityFlags.ClearTop | ActivityFlags.NewTask; } #if __ANDROID_24__ if (Platform.HasApiLevelN && options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) { if (tabsFlags.HasValue) { tabsFlags |= ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; } else { tabsFlags = ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; } } #endif // Check if there's flags specified to use if (tabsFlags.HasValue) { tabsIntent.Intent.SetFlags(tabsFlags.Value); } tabsIntent.LaunchUrl(context, nativeUri); break; case BrowserLaunchMode.External: var intent = new Intent(Intent.ActionView, nativeUri); var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; #if __ANDROID_24__ if (Platform.HasApiLevelN && options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) { flags |= ActivityFlags.LaunchAdjacent; } #endif intent.SetFlags(flags); if (!Platform.IsIntentSupported(intent)) { throw new FeatureNotSupportedException(); } Platform.AppContext.StartActivity(intent); break; } return(Task.FromResult(true)); }