firebase-admin-dotnet
firebase-admin-dotnet copied to clipboard
Execute "onMessageReceived" on background
[READ] Step 1: Are you in the right place?
- I like to send a "data message" throw this nuget (no notification), so the "onMessageReceived" method was call on android in even in background.
- Actually, I use HTTP legacy URI : https://fcm.googleapis.com/fcm/send and I'm able to send "data message" and "notification message"
- I try to use "HTTP v1" instead, but I can't send "data message", I always receive a "notification message"
[REQUIRED] Step 2: Describe your environment
- Operating System version: ubuntu 22.04
- Firebase SDK version: 2.3.0
- Firebase Product: messaging
- .NET version: net6.0
- OS: linux
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Send a message with :
var message = new Message()
{
Token = myToken,
Notification = new Notification
{
Body = notification.Message.GetLanguage(device.DeviceLanguage),
Title = notification.Title.GetLanguage(device.DeviceLanguage),
},
Android = new AndroidConfig
{
TimeToLive = TimeSpan.FromHours(1),
Priority = Priority.High,
Notification = new AndroidNotification
{
ChannelId = GetAndroidChannelId("alertChannel", soundName)
}
},
Data = new Dictionary<string, string>() { }
};
var fcmResponse = await FirebaseMessaging.DefaultInstance.SendAsync(message);
I receive a "notification message" :)
var message = new Message()
{
Token = myToken,
Android = new AndroidConfig
{
TimeToLive = TimeSpan.FromHours(1),
Priority = Priority.High,
Notification = new AndroidNotification
{
ChannelId = GetAndroidChannelId("alertChannel", soundName)
}
},
Data = new Dictionary<string, string>() { }
};
var fcmResponse = await FirebaseMessaging.DefaultInstance.SendAsync(message);
I receive a "notification message" not a "data message" :(
I aslo try to force the Notification property as null. But I had the same result
var message = new Message()
{
Token = myToken,
Notification = null,
...
There is something I can do ?
@chong-shao Is there any follow up about this problem?
Same problem for me. Is there any solution available ?
It seams that I have the same issue, any news ?
I am having the same issue. The data message doesn't reach onMessageReceived if the android app is in the background. Many have suggested a solution here: https://stackoverflow.com/questions/48451761/firebase-message-with-high-priority-not-waking-device-from-doze-android-6
The solution is to add priority at both Message level and at AndroidOptions level.
{
"priority": "high", // legacy HTTP protocol (this can also be set to 10)
"android": {
"priority": "high" // HTTP v1 protocol
}
}
Can we have a workaround or a fix for this? It is very critical issue.
{ "priority": "high", // legacy HTTP protocol (this can also be set to 10) "android": { "priority": "high" // HTTP v1 protocol } }
I modified the code to have "priority" as part of Message object, but this didn't work. Received error from the server that the json payload is invalid.