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