I’m using Xamarin.Forms with Parse clients as supplied by Sashi.do.
When I send pushes, they generally work across both iOS and Android, with one big exception: Android apps that have been fully terminated.
These seem to work only around 40% of the time.
This is my Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.concierxge.Android" android:versionName="4.1.4" android:versionCode="27">
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="33" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application android:icon="@mipmap/ic_launcher" android:label="CONCIERxGE">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_notification" />
<receiver android:name="parse.ParsePushBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
<category android:name="com.concierxge.Android" />
</intent-filter>
</receiver>
</application>
<uses-feature android:name="android.hardware.telephony" android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.concierxge.Android.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.concierxge.Android.permission.C2D_MESSAGE" />
</manifest>
And this is how I’m initializing CrossGeeks’ Firebase Plugin nuget in my Android MainLauncher activity (note that Android notifications weren’t working at all until I implemented CrossFirebasePushNotification):
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
////Change for your default notification channel id here
FirebasePushNotificationManager
.DefaultNotificationChannelId =
"FirebasePushNotificationChannel";
FirebasePushNotificationManager.
DefaultNotificationChannelName = "SecondChannel";
}
// Enable Firebase verbose logging
firebaseAnalytics = FirebaseAnalytics.GetInstance(this);
firebaseAnalytics.SetAnalyticsCollectionEnabled(true);
//If debug you should reset the token each time.
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this, false);
#endif
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.Subscribe("Todos");
FirebasePushNotificationManager.IconResource =
Resource.Drawable.ic_notification;
FirebasePushNotificationManager.LargeIconResource =
Resource.Drawable.ic_notification;
FirebasePushNotificationManager.DefaultNotificationChannelImportance
= NotificationImportance.Max;
CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
{
//custom token-logging code
};
CrossFirebasePushNotification.Current
.OnNotificationOpened += (s, p) =>
{
foreach (var data in p.Data)
{
//output data to console
}
};
//Handle notification when app is closed here
CrossFirebasePushNotification.Current.OnNotificationReceived +=
(sender, payload) =>
{
//code that logs having received and handled notification
//...
};
I have also implemented this in my main Parse-setup class:
ParsePush.ParsePushNotificationReceived += (obj, args) =>
{
//code that logs having received and handled notification
//...
};
…and it’s worth noting that ParsePush.ParsePushNotificationReceived
does not fire, only CrossFirebasePushNotification.Current.OnNotificationReceived
fires…