0

I'm trying to get notifications going in a Xamarin app, initially in the Android side, then I'll do the iOS. I downloaded the android sample app and it works just fine. However, when I try to implement the same in my own app, although I get no error I also get no notification.

I'm initially trying to simply create a test one in the main activity but I am wondering if it has anything to do with this being a master-detail type app.

Do I have to give the notification builder and manager different contexts and not the main activity as the sample shows? Unfortunately I have not managed to find an example master-detail app implementing notifications.

The main activity OnCreate() is as follows...

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        AndroidContext = this;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);

        UserDialogs.Init(this);

        LoadApplication(new App()); //<- setup master-detail forms

        IsPlayServicesAvailable();

        FirebaseApp.InitializeApp(this);
        var refreshedToken = FirebaseInstanceId.Instance.Token;

        var notificationBuilder = new Notification.Builder(this)
                .SetSmallIcon(Resource.Drawable.icon)
                .SetContentTitle("myStaff Message")
                .SetContentText("test")
                .SetAutoCancel(true);

        var notificationManager = NotificationManager.FromContext(this);

        notificationManager.Notify(0, notificationBuilder.Build());            
    }

Could I please ask that people refrain from responding with "you should use xyz plugin" or "use nuget abc..." or similar. While I appreciate that there are plenty of plugins which can do this, I want to understand what is going wrong with my code and not simply avoid/workaround the problem.

Edit: Ok, so this goes deeper than I realised. I have now tried with two different plugins too - same result in both cases, no error but no notification. This is just nuts. Going to go back a few weeks in my code and try there then iterate in to where (when) it stops, perhaps that will give me a clue to what's blocking it

Mike
  • 2,120
  • 1
  • 23
  • 40

1 Answers1

0

So, upon further investigation and digging out older devices, it would appear that this is an Oreo issue.

It appears that the official documentation is lacking and the demo projects do not allow for Channels and this is where the problem lies. It has nothing to do with master-detail - my code works just fine (all versions) when run on an older device, just not on 8.0+ - now I just have to fix it.

Edit: based on the post by kylewhittington in this github thread (about the 8th post) I have now managed to code a solution which works in both Oreo and older version of Android. Just have to add the code for iOS.

Mike
  • 2,120
  • 1
  • 23
  • 40