firebase-admin-dotnet icon indicating copy to clipboard operation
firebase-admin-dotnet copied to clipboard

Execute "onMessageReceived" on background

Open mickjol opened this issue 2 years ago • 3 comments

[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 ?

mickjol avatar May 12 '22 17:05 mickjol

@chong-shao Is there any follow up about this problem?

iamkinetic avatar May 30 '22 17:05 iamkinetic

Same problem for me. Is there any solution available ?

philipperobertgh avatar May 30 '22 17:05 philipperobertgh

It seams that I have the same issue, any news ?

Josbleuet avatar May 31 '22 20:05 Josbleuet

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.

gautambjain avatar Nov 28 '22 03:11 gautambjain

{
    "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.

gautambjain avatar Dec 01 '22 17:12 gautambjain