'Activity1.OnNewIntent(Content.Intent)': 没有找到合适的方法来覆盖

'Activity1.OnNewIntent(Content.Intent)': no suitable method found to override

我在我的 MonoGame Android 项目中实施了 App Center 推送通知并且一切似乎都正常,因为我在我的 Android 设备上收到了从我的 App Center 帐户发送的通知。但在本教程中,他们提到如果您的 LaunchMode 是 SingleInstance,您应该将此代码添加到您的 Acitivity class,但代码不起作用。我收到两条错误消息。

Tutorial: see Intercept push notifications, Additional setup

当您有一个没有启动画面的 Android 项目时,是否真的需要这段代码?如果我在我的项目中添加启动画面会有什么不同吗?

此代码的作用是什么?如果需要,我如何在 MonoGame Android 项目中使用它?

     protected override void OnNewIntent(Android.Content.Intent intent)
     {
         base.OnNewIntent(intent);
         Push.CheckLaunchedFromNotification(this, intent);
     }

The type or namespace name 'Content' does not exist in the namespace (are you missing an assembly reference?)

'Activity1.OnNewIntent(Content.Intent)': no suitable method found to override (CS0115)

    using Android.App;
    using Android.Content.PM;
    using Android.OS;
    using Android.Views;
    using Microsoft.AppCenter;
    using Microsoft.AppCenter.Analytics;
    using Microsoft.AppCenter.Crashes;
    using Microsoft.AppCenter.Push;

    namespace Newapp.Android
    {
        [Activity(Label = "Newapp.Android"
            , MainLauncher = true
            , Icon = "@drawable/icon"
            , Theme = "@style/Theme.Splash"
            , AlwaysRetainTaskState = true
            , LaunchMode = LaunchMode.SingleInstance
            , ScreenOrientation = ScreenOrientation.FullUser
            , ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]
        public class Activity1 : Microsoft.Xna.Framework.AndroidGameActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
                if (!AppCenter.Configured)
                {
                    Push.PushNotificationReceived += (sender, e) =>
                    {
                        // Add the notification message and title to the message
                        var summary = $"Push notification received:" +
                                            $"\n\tNotification title: {e.Title}" +
                                            $"\n\tMessage: {e.Message}";

                        // If there is custom data associated with the notification,
                        // print the entries
                        if (e.CustomData != null)
                        {
                            summary += "\n\tCustom data:\n";
                            foreach (var key in e.CustomData.Keys)
                            {
                                summary += $"\t\t{key} : {e.CustomData[key]}\n";
                            }
                        }

                        // Send the notification summary to debug output
                        System.Diagnostics.Debug.WriteLine(summary);
                    };
                }

                AppCenter.Start("{Your App Secret}", typeof(Analytics), typeof(Crashes), typeof(Push));

                var g = new Game1();
                SetContentView((View)g.Services.GetService(typeof(View)));
                g.Run();
            }

         protected override void OnNewIntent(Android.Content.Intent intent)
         {
             base.OnNewIntent(intent);
             Push.CheckLaunchedFromNotification(this, intent);
         }
        }
    }

您看到编译器错误是因为您项目中的名称空间以 Android 结尾,所以它试图找到 NewApp.Android.Content.Intent 而不是 Android.Content.Intent。您可以通过将命名空间更改为不以 Android 结尾来修复错误,或者您可以在引用全局 Android 命名空间时使用 global::

protected override void OnNewIntent(global::Android.Content.Intent intent)
{
    base.OnNewIntent(intent);
    Push.CheckLaunchedFromNotification(this, intent);
}