0

I'm doing a Xamarin Forms application and have all wired to integrate with MSAL.net. In Android, when I launch the application from the drawer, everything works fine, the authentication it's done and the MainActivity.OnActivityResult it's called (it's where I have AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(a_RequestCode, a_ResultCode, a_Data)).

This application can be launched also from an AppLink but when I launch the application this way, then after the authentication it's done, the MainActivity.OnActivityResult isn't called and an empty form with just the title of the application it's shown.

I'm using as WithParentActivityOrWindow parameter the MainActivity. Any idea why using the link method doesn't work?

Thanks

EDIT: This is how my MainActivity looks like:

[Activity(Label = "MyApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", 
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]

[IntentFilter(new[] { Android.Content.Intent.ActionView },
AutoVerify = true, Categories = new[]
{
  Android.Content.Intent.CategoryDefault,
  Android.Content.Intent.CategoryBrowsable
},
  DataScheme = "https", DataPathPrefix = "/",
  DataHost = "MyApp.com"
)]

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
private App _App;

protected override void OnCreate(Bundle savedInstanceState)
{
  // TODO: If not shell remove this?
  TabLayoutResource = Resource.Layout.Tabbar;
  ToolbarResource = Resource.Layout.Toolbar;

  base.OnCreate(savedInstanceState);

  CrossCurrentActivity.Current.Init(this, savedInstanceState);

  global::Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", 
    "FastRenderers_Experimental");
  Xamarin.Essentials.Platform.Init(this, savedInstanceState);
  global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

  AnimationViewRenderer.Init();

  UserDialogs.Init(() => this);

  Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);

  Plugin.InputKit.Platforms.Droid.Config.Init(this, savedInstanceState);

  FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);

  CarouselViewRenderer.Init();

  // Exception handler
  AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
  TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
  AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironmentOnUnhandledException;

  // Pass the activity to be used as OAuth return 
  _App = new App(this);
  LoadApplication(_App);
}

private void AndroidEnvironmentOnUnhandledException(object a_Sender, RaiseThrowableEventArgs a_Args)
{
  //a_Args.Handled = await _App.ShowUnhandledExceptionAsync(a_Sender, a_Args.Exception);
}

private void TaskSchedulerOnUnobservedTaskException(object a_Sender, UnobservedTaskExceptionEventArgs a_Args)
{
  _App.ShowUnhandledExceptionAsync(a_Sender, a_Args.Exception);
}

private void OnUnhandledException(object a_Sender, UnhandledExceptionEventArgs a_Exception)
{
  //_App.ShowUnhandledExceptionAsync(a_Sender, a_Exception.ExceptionObject as Exception);
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions,
  [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
  Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
  Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults); 
  base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

public override void OnBackPressed()
{
  if (Rg.Plugins.Popup.Services.PopupNavigation.Instance.PopupStack.Count > 0)
  {
    Rg.Plugins.Popup.Popup.SendBackPressed(base.OnBackPressed);
  }
  else
  {
    base.OnBackPressed();
  }
}

protected override void OnActivityResult(int a_RequestCode, Result a_ResultCode, [CanBeNull] Intent a_Data)
{
  base.OnActivityResult(a_RequestCode, a_ResultCode, a_Data);
  AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(a_RequestCode, a_ResultCode, a_Data);

  MultiMediaService.SharedInstance.OnActivityResult(a_RequestCode, a_ResultCode, a_Data);
}
  • You could override the method `OnNewIntent` to check if the app can receive the callback when been launched by the link. And you would better post the full code in MainActivity to check the issue better . – Lucas Zhang Feb 03 '20 at 05:00
  • I have added my MainActivity. Also found there it is a bug filled at [Github](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1508) – David Sancho Feb 04 '20 at 06:46
  • OK , we will focus on it . – Lucas Zhang Feb 04 '20 at 06:47

0 Answers0