Closed andyzukunft closed 1 year ago
I have good news!
The problem has been identified. There are actually several:
Developer warning for package "***" Failed to post notification to channel "null". See log for more details
in Android when I send a notification to the app.
I fixed it by removing the Build.VERSION.SdkInt check (Build.VERSION.SdkInt >= BuildVersionCodes.O
) for before the call to CreateNotificationChannel() in MainActivity.cs. Android 8.1 is currently my minimum so this check is always fulfilled however the CreateNotificationChannel-code was not executed on an Android 11 emulator. Have no clue why this happens. Super weird.android.permission.POST_NOTIFICATION
(more information) has to be added to the AndroidManifest.xml and has to be requested during startup.
Current MAUI implementation does not support this permission. So I suggest to add the following to the Android Activity (e.g. where/before the channel is created).
if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
{
#pragma warning disable CA1416 // Validate platform compatibility
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.PostNotifications) != Permission.Granted)
{
ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.PostNotifications }, 0);
}
#pragma warning restore CA1416 // Validate platform compatibility
}
All of this has been tested with the following FCM message (I upgraded my backend to support the new Google REST v1 backend):
"message": {
"token": "token",
"android": {
"notification": {
"title": "Message",
"body": "Test1"
},
"priority": "high",
"ttl": "86400s"
}
}
@TobiasBuchholz Can you please add the information (Problem 1: how to test FCM, Problem 2: possible solution if FCM notifications are not working on closed app, Problem 3: Android 13 additions, examle FCM message for testing) to your documentation?
I will keep the issue open. Please feel free to close it at your convenience.
@andyzukunft thanks for this information, you may want to add this information and request a pull.
any news about this?
I've made a reference to @andyzukunft's helpful comment in the troubleshooting section of the cloud messaging documentation.
Hey all,
I migrated my in-development app from Xamarin to MAUI and moved from Plugin.FirebasePushNotification to Plugin.Firebase. With the Plugin.FirebaasePushNotification the notifications are shown when the app is opened, in background and closed. I did not change the test notification (message directed to fcm token) being sent from my backend from the last time I tested this feature (as far as I can tell).
During testing (atm on Android) I realised that the notification is received and displayed just fine when the app is opened or in background. However if the app is closed the notification is not displayed. Did I miss something or is this a known limitation?
AndroidManifest.xml
MainActivity.cs
Fcm Message
I tried both variations. My regular variation is the one without Notification because as far as I know only messages without notification are displayed when the app is closed.