protected override void OnResume() { base.OnResume(); if (!started) { started = true; var uri = Android.Net.Uri.Parse(Intent.GetStringExtra(BrowserImpl.StartUrlKey)); var name = CustomTabsHelper.GetPackageNameToUse(this); if (name != null) { var manager = new CustomTabsActivityManager(this); var intent = new CustomTabsIntent.Builder(manager.Session).Build(); intent.Intent.SetPackage(name); intent.Intent.AddFlags(ActivityFlags.NoHistory); intent.LaunchUrl(this, uri); } else { var intent = new Intent(Intent.ActionView, uri); StartActivity(intent); } return; } started = false; Callbacks?.Invoke(Intent.DataString ?? BrowserImpl.UserCancelResponse); Finish(); }
public static void ShowWebPage(Activity activity, string url) { var intent = new CustomTabsIntent.Builder() .SetShowTitle(true) .SetToolbarColor(ContextCompat.GetColor(activity, Resource.Color.theme500)) .Build(); intent.LaunchUrl(activity, Android.Net.Uri.Parse(url)); }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); var activity = this.Context as Activity; OAuth2Authenticator auth = null; if (Config.IsUsingNativeUI) { auth = new OAuth2Authenticator( clientId: Config.ClientId, clientSecret: Config.ClientSecret, scope: Config.Scope, authorizeUrl: new Uri(Config.AuthorizeUrl), redirectUrl: new Uri(Config.RedirectUrl), accessTokenUrl: new Uri(Config.AccesTokenUrl), getUsernameAsync: null, isUsingNativeUI: Config.IsUsingNativeUI ); } else { auth = new OAuth2Authenticator( clientId: Config.ClientId, scope: Config.Scope, authorizeUrl: new Uri(Config.AuthorizeUrl), redirectUrl: new Uri(Config.RedirectUrl), getUsernameAsync: null, isUsingNativeUI: Config.IsUsingNativeUI ); } auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { var oAuthToken = new OAuthToken() { AccessToken = eventArgs.Account.Properties["access_token"] }; MessagingCenter.Send <object, OAuthToken>(this, "GetUser", oAuthToken); } else { App.Current.MainPage = new NavigationPage(new LoginPage()); } }; var authActivity = new CustomTabsIntent.Builder().Build(); authActivity.Intent = auth.GetUI(activity); authActivity.LaunchUrl(activity, Android.Net.Uri.Parse(Config.AuthorizeUrl)); Forms.Context.StartActivity(authActivity.Intent); //activity.StartActivity(auth.GetUI(activity)); }
public Task ShowWebPageAsync(Uri uri, CancellationToken cancellationToken) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } var tabsIntent = new CustomTabsIntent.Builder().Build(); tabsIntent.Intent.SetFlags(ActivityFlags.ClearTop); tabsIntent.Intent.SetFlags(ActivityFlags.NewTask); tabsIntent.LaunchUrl(Application.Context, AndroidUri.Parse(uri.AbsoluteUri)); return(Task.CompletedTask); }
/// <summary> /// /// </summary> protected override void OnResume() { base.OnResume(); if (_restarted) { cancelRequest(); return; } _restarted = true; string chromePackageWithCustomTabSupport = GetChromePackageWithCustomTabSupport(ApplicationContext); if (string.IsNullOrEmpty(chromePackageWithCustomTabSupport)) { Intent browserIntent = new Intent(Intent.ActionView, Uri.Parse(_requestUrl)); browserIntent.AddCategory(Intent.CategoryBrowsable); RequestContext.Logger.Warning( "Browser with custom tabs package not available. " + "Launching with alternate browser. See https://aka.ms/msal-net-system-browsers for details."); try { StartActivity(browserIntent); } catch (ActivityNotFoundException ex) { throw new MsalClientException( MsalError.AndroidActivityNotFound, MsalErrorMessage.AndroidActivityNotFound, ex); } } else { RequestContext.Logger.Info( string.Format( CultureInfo.CurrentCulture, "Browser with custom tabs package available. Using {0}. ", chromePackageWithCustomTabSupport)); CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().Build(); customTabsIntent.Intent.SetPackage(chromePackageWithCustomTabSupport); customTabsIntent.LaunchUrl(this, Uri.Parse(_requestUrl)); } }
public void MoveTo(string host) { var context = Android.App.Application.Context; CustomTabsIntent builder = new CustomTabsIntent.Builder() //.AddDefaultShareMenuItem() // dont work //.SetCloseButtonIcon() // .SetToolbarColor(Android.Graphics.Color.ParseColor("#43A047")) .EnableUrlBarHiding() //*/ .Build(); // builder.Intent.AddFlags(ActivityFlags.NewTask); builder.LaunchUrl(MainActivity.Instance, Android.Net.Uri.Parse(host)); /* * Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(host)); * Android.App.Application.Context.StartActivity(intent); * // throw new Exception("Obsolete");//*/ }
private async void StartNewActivity(Type newActivity, DeviceType deviceType) { _bleDevicesRecords = await SqlHelper <BluetoothDeviceRecords> .CreateAsync(); var list = await _bleDevicesRecords.QueryValuations( "select * from BluetoothDeviceRecords"); if ((from c in list where c.DeviceType == deviceType select new { c.Name, c.Address, c.DeviceType }).Any()) { Activity.StartActivity(newActivity); } else { if (deviceType == DeviceType.SmartBand) { const string url = "https://www.fitbit.com/oauth2/authorize?" + /*"grant_type=authorization_code"+*/ "response_type=code" + "&client_id=22CZRL" + "&redirect_uri=fittauth%3A%2F%2Ffinish" + "&scope=activity%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight" + "&prompt=login" + "&expires_in=31536000"; CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().Build(); customTabsIntent.LaunchUrl(Activity, Uri.Parse(url)); } else { using AlertDialog alertDialog = new AlertDialog.Builder(Activity, Resource.Style.AppTheme_Dialog).Create(); alertDialog.SetTitle("Avertisment"); alertDialog.SetMessage("Nu aveti niciun dispozitiv inregistrat!"); alertDialog.SetButton("OK", delegate { Activity.StartActivity(typeof(DevicesManagementActivity)); }); alertDialog.Show(); } } }
/// <summary> /// /// </summary> protected override void OnResume() { base.OnResume(); if (_restarted) { cancelRequest(); return; } _restarted = true; /*_customTabsActivityManager = new CustomTabsActivityManager(this); * _customTabsActivityManager.CustomTabsServiceConnected += delegate { _customTabsActivityManager.LaunchUrl(_requestUrl); };*/ string chromePackageWithCustomTabSupport = GetChromePackageWithCustomTabSupport(ApplicationContext); if (string.IsNullOrEmpty(chromePackageWithCustomTabSupport)) { string chromePackage = GetChromePackage(); if (string.IsNullOrEmpty(chromePackage)) { throw new MsalException(MsalErrorAndroidEx.ChromeNotInstalled, "Chrome is not installed on the device, cannot proceed with auth"); } Intent browserIntent = new Intent(Intent.ActionView); browserIntent.SetData(Uri.Parse(_requestUrl)); browserIntent.SetPackage(chromePackage); browserIntent.AddCategory(Intent.CategoryBrowsable); StartActivity(browserIntent); } else { CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().Build(); customTabsIntent.Intent.SetPackage(chromePackageWithCustomTabSupport); customTabsIntent.LaunchUrl(this, Uri.Parse(_requestUrl)); } }
public static void Init(Activity activity) { if (isInitialised) { return; } OnLaunchRequested += (uri, accentColour) => { var manager = CustomTabsActivityManager.From(activity); manager.CustomTabsServiceConnected += customTabServiceConnected; if (!manager.BindService()) { // Fall back to opening the system browser if necessary var browserIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(uri)); activity.StartActivity(browserIntent); } void customTabServiceConnected(ComponentName name, CustomTabsClient client) { manager.CustomTabsServiceConnected -= customTabServiceConnected; var intent = new CustomTabsIntent.Builder() .SetDefaultColorSchemeParams(new CustomTabColorSchemeParams.Builder() .SetToolbarColor(accentColour) .SetNavigationBarColor(accentColour) .Build()) .Build(); intent.Intent.AddFlags(ActivityFlags.SingleTop | ActivityFlags.NoHistory | ActivityFlags.NewTask); CustomTabsHelper.AddKeepAliveExtra(activity, intent.Intent); intent.LaunchUrl(activity, Android.Net.Uri.Parse(uri)); } }; isInitialised = true; } }
protected override async void OnResume() { base.OnResume(); if (_loginSequenceEnded) { _tokenSource = new CancellationTokenSource(); await Presenter.Login(_tokenSource.Token); } else if (!_loginSequenceStarted) { var intentBuilder = new CustomTabsIntent.Builder() .Build(); var authUrlTemplate = Resources.GetString(Resource.String.AniListAuthorizeUri); _loginSequenceStarted = true; intentBuilder.LaunchUrl(this, Android.Net.Uri.Parse(Presenter.GetRedirectUrl(authUrlTemplate))); } else { OnLoginAborted(); } }
public void LaunchCunstomTabsWithUrlDefault() { //....................................................... // Launching CustomTabs and url - minimal if ( CustomTabsConfiguration.CustomTabActivityHelper != null && CustomTabsConfiguration.CustomTabsIntent != null && CustomTabsConfiguration.UriAndroidOS != null ) { CustomTabsConfiguration .CustomTabsIntent .Intent.AddFlags(CustomTabsConfiguration.ActivityFlags); CustomTabsConfiguration .CustomTabActivityHelper .LaunchUrlWithCustomTabsOrFallback ( // Activity/Context this, // CustomTabInten CustomTabsConfiguration.CustomTabsIntent, CustomTabsConfiguration.PackageForCustomTabs, CustomTabsConfiguration.UriAndroidOS, // Fallback if CustomTabs do not exis CustomTabsConfiguration.WebViewFallback ); } else { // plain CustomTabs no customizations CustomTabsIntent i = new CustomTabsIntent.Builder().Build(); i.Intent.AddFlags(CustomTabsConfiguration.ActivityFlags); i.LaunchUrl(this, CustomTabsConfiguration.UriAndroidOS); } //....................................................... // Launching CustomTabs and url - if WarmUp and Prefetching is used /* */ //--------------------------------------------------------------------------------- // // Restore the UI state or start over // /* * if (savedInstanceState != null) * { * //webView.RestoreState(savedInstanceState); * } * else * { * if (Intent.GetBooleanExtra("ClearCookies", true)) * { * WebAuthenticator.ClearCookies(); * } * BeginLoadingInitialUrl(); * } */ return; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // // Load the state either from a configuration change or from the intent. // // * state = LastNonConfigurationInstance as State; if (state == null && Intent.HasExtra("StateKey")) { var stateKey = Intent.GetStringExtra("StateKey"); state = StateRepo.Remove(stateKey); } if (state == null) { Finish(); return; } //Title = state.Authenticator.Title; // // Watch for completion // state.Authenticator.Completed += (s, e) => { SetResult(e.IsAuthenticated ? Result.Ok : Result.Canceled); #region ///------------------------------------------------------------------------------------------------- /// Pull Request - manually added/fixed /// Added IsAuthenticated check #88 /// https://github.com/xamarin/Xamarin.Auth/pull/88 if (e.IsAuthenticated) { if (state.Authenticator.GetAccountResult != null) { var accountResult = state.Authenticator.GetAccountResult(e.Account); Bundle result = new Bundle(); result.PutString(global::Android.Accounts.AccountManager.KeyAccountType, accountResult.AccountType); result.PutString(global::Android.Accounts.AccountManager.KeyAccountName, accountResult.Name); result.PutString(global::Android.Accounts.AccountManager.KeyAuthtoken, accountResult.Token); result.PutString(global::Android.Accounts.AccountManager.KeyAccountAuthenticatorResponse, e.Account.Serialize()); SetAccountAuthenticatorResult(result); } } ///------------------------------------------------------------------------------------------------- #endregion CloseCustomTabs(); }; state.Authenticator.Error += (s, e) => { if (!state.Authenticator.ShowErrors) { return; } if (e.Exception != null) { this.ShowError("Authentication Error e.Exception = ", e.Exception); } else { this.ShowError("Authentication Error e.Message = ", e.Message); } BeginLoadingInitialUrl(); }; // Build the UI CustomTabsConfiguration.Initialize(this); CustomTabsConfiguration.UICustomization(); //....................................................... // Launching CustomTabs and url - minimal if ( CustomTabsConfiguration.CustomTabActivityHelper != null && CustomTabsConfiguration.CustomTabsIntent != null && CustomTabsConfiguration.UriAndroidOS != null ) { CustomTabsConfiguration.CustomTabsIntent .Intent.AddFlags ( global::Android.Content.ActivityFlags.NoHistory | global::Android.Content.ActivityFlags.SingleTop | global::Android.Content.ActivityFlags.NewTask ); CustomTabsConfiguration .CustomTabActivityHelper .LaunchUrlWithCustomTabsOrFallback ( // Activity/Context this, // CustomTabIntent CustomTabsConfiguration.CustomTabsIntent, CustomTabsConfiguration.UriAndroidOS, // Fallback if CustomTabs do not exist CustomTabsConfiguration.WebViewFallback ); } else { // plain CustomTabs no customizations CustomTabsIntent i = new CustomTabsIntent.Builder().Build(); i.Intent.AddFlags ( global::Android.Content.ActivityFlags.NoHistory | global::Android.Content.ActivityFlags.SingleTop | global::Android.Content.ActivityFlags.NewTask ); i.LaunchUrl(this, CustomTabsConfiguration.UriAndroidOS); } //....................................................... // Launching CustomTabs and url - if WarmUp and Prefetching is used /* */ //--------------------------------------------------------------------------------- // // Restore the UI state or start over // /* * if (savedInstanceState != null) * { * //webView.RestoreState(savedInstanceState); * } * else * { * if (Intent.GetBooleanExtra("ClearCookies", true)) * { * WebAuthenticator.ClearCookies(); * } * BeginLoadingInitialUrl(); * } */ return; }