I made several attempts to send Push Notification and none of them I could see in my App. I always thought until now, that I was wrong. But I followed two step by step and I saw that with the guys it was working and not with me. So I started to think otherwise, that either the firebase did not fire properly or my equipment, for reasons hitherto unknown, is not receiving. How did I come to this conclusion? Is that when I starto the application, I put break in several points and at the moment that the app goes up, on the OnRegistered application to and there I get the token generated. Once I unregistered and registered and generated a new message and it was with the previous token and not the new generated, then when I triggered the notification, I gave the firebase error of: / p>
Message status: failed
I placed the valid token, gave the message Sent and in the App I can not get it. Something is blocking the receipt and I do not know what it is. I am suspicious of Security Master , Vysor, My KNOX and etc or Firebase itself, but I'm not sure. Here's the code I've done now, which reported it all: Startup class
[Application]
public class PushNotificationAppStater : Application
{
public static Context AppContext;
public PushNotificationAppStater(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
public override void OnCreate()
{
base.OnCreate();
AppContext = this.ApplicationContext;
//TODO: Initialize CrossPushNotification Plugin
//TODO: Replace string parameter with your Android SENDER ID
//TODO: Specify the listener class implementing IPushNotificationListener interface in the Initialize generic
CrossPushNotification.Initialize<CrossPushNotificationListener>("806431458293");
StartPushService();
}
public static void StartPushService()
{
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
public static void StopPushService()
{
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
}
Message listener class and status
public class CrossPushNotificationListener : IPushNotificationListener
{
public void OnError(string message, DeviceType deviceType)
{
}
public void OnMessage(JObject values, DeviceType deviceType)
{
}
public void OnRegistered(string token, DeviceType deviceType)
{
}
public void OnUnregistered(DeviceType deviceType)
{
}
public bool ShouldShowNotification()
{
return true;
}
}
MainActivity
[Activity(Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
My App.xaml.cs public partial class App: Application { public App () { InitializeComponent ();
MainPage = new App1.MainPage();
}
protected override void OnStart()
{
CrossPushNotification.Current.Unregister();
CrossPushNotification.Current.Register();
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
My android.manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.global.app.br" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<application android:label="App1.Android" android:icon="@drawable/icon">
<service
android:name=".Messaging.FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
The rest has google-services.json with build option for google-services.json and the installed package is: Xam.Plugin.PushNotification NewtonSoft.json
These were the only plugins I installed. What could be the problem?