Johnny
Johnny

Reputation: 85

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

I implemented App Center push notifications in my MonoGame Android project and everything seems to work, because I receive the notifications on my Android device that I have sent from my App Center account. But in this tutorial, they mention that you should add this code to your Acitivity class if your LaunchMode is SingleInstance, but the code isn't working. I get two error messages.

Tutorial: see Intercept push notifications, Additional setup

Is this code really necessary when you have an Android project without a splashscreen? Would it make a difference if I add a splashscreen to my project?

What is this code doing and how could I use it in a MonoGame Android project if it would be necessary?

     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);
         }
        }
    }

Upvotes: 0

Views: 417

Answers (1)

Trevor Balcom
Trevor Balcom

Reputation: 3888

You're seeing the compiler error because the namespace in your project ends with Android so it's trying to find NewApp.Android.Content.Intent not Android.Content.Intent. You can fix the error by changing your namespace to not end with Android, or you can use global:: when referencing the global Android namespace:

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

Upvotes: 1

Related Questions