簡體   English   中英

'Activity1.OnNewIntent(Content.Intent)':找不到合適的方法來覆蓋

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

我在MonoGame Android項目中實現了App Center推送通知,並且一切似乎正常,因為我在Android設備上收到了從App Center帳戶發送的通知。 但是在本教程中,他們提到如果LaunchMode為SingleInstance,則應將此代碼添加到Acitivity類中,但是代碼不起作用。 我收到兩個錯誤消息。

教程:請參閱攔截推送通知,其他設置

當您擁有沒有啟動畫面的Android項目時,此代碼真的必要嗎? 如果將閃屏添加到項目中,會有所不同嗎?

這段代碼在做什么?如果有必要,我該如何在MonoGame Android項目中使用它?

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

類型或名稱空間名稱“ Content”在名稱空間中不存在(您是否缺少程序集引用?)

'Activity1.OnNewIntent(Content.Intent)':找不到合適的方法來覆蓋(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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM