我正在做一个 Xamarin Forms 应用程序,并且已经与MSAL.net
. 在 Android 中,当我从抽屉中启动应用程序时,一切正常,它完成了身份验证并被
MainActivity.OnActivityResult
调用(这是我拥有 AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(a_RequestCode, a_ResultCode, a_Data))
.
此应用程序也可以从 AppLink 启动,但是当我以这种方式启动应用程序时,在完成身份验证后,MainActivity.OnActivityResult
不会调用它,并且只显示一个带有应用程序标题的空表单。
我WithParentActivityOrWindow
将MainActivity
. 知道为什么使用链接方法不起作用吗?
谢谢
编辑:这就是我的 MainActivity 的样子:
[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);
}