1

I need to send message that contains both 'data' and 'notification' payload. The message will be sent to a topic which subscriber can be from iOS or Android device.

In Android, is there any way for message with both notification and data payload to be always received at onMessageReceived instead of at system tray and intent extras? This including when the app is on background.

I can't remove the notification payload (send only 'data' payload) because the notification payload needed for iOS subscriber

AL.
  • 36,815
  • 10
  • 142
  • 281
nesniv
  • 11
  • 2
  • Basing from the [docs](https://firebase.google.com/docs/notifications/android/console-device#receive_and_handle_messages), receiving the message when in background is the behavior of Android itself. Not sure if you can alter that out. What I'm thinking of instead is, maybe there is a way to check the System Tray/extras intent then direct the flow to the same method that is in you `onMessageReceived()`. Just a thought tho. – AL. Sep 14 '16 at 02:00

1 Answers1

0

Maybe if it helps, this is the (C#) objects I used to send notifications for both IOS and Android.

    internal class jsonObj
    {
        //public bool delay_while_idle { get; set; }
        public data data { get; set; }
        public notification notification { get; set; }
        public string to { get; set; }
        public string priority { get; set; }
    }

    internal class data
    {
        public int Id { get; set; }
        public int commentId { get; set; }
        public string type { get; set; }
        public string DisplayName { get; set; }
        public string licensePlateCode { get; set; }
        public int licensePlateId { get; set; }
        public string text { get; set; }
    }

    internal class notification
    {
        public string title { get; set; }
        public string body { get; set; }
        public string sound { get; set; }
        public string badge { get; set; }
        [JsonProperty("content-available")]
        public string contentAvailable { get; set; }
    }

At the moment of writing that code I used the old WakefulBroadcastReceiver and IntentService in android, which is not recommended anymore. But if interested, it looked like this question

EDIT: OP commented about this post on github. The same issue is described there which is still not fixed (September 2016). Workarounds can be found there, you have to send different requests for IOS and Android.

Community
  • 1
  • 1
CularBytes
  • 9,924
  • 8
  • 76
  • 101
  • 1
    I think I found the issue for this this problem. It's because "The current implementation doesn't allow to send a message that is simultaneously a display notification for ios and a silent notification for android." ref : https://github.com/google/gcm/issues/63 So I think the only possible solution for now is to send different payload between iOS and android. – nesniv Sep 15 '16 at 11:20