This might sound like an Android coding issue, but I'd like to validate that what I'm doing in APEX is correct.
I'm trying to send messages to an Android device through APEX using Messaging.PushNotification.
The app is using the Salesforce Android SDK 9.0.0
When the app is in the foreground, I can see the message arrive, but when the app is in the background, or not running the message doesn't arrive. I'm expecting the message to appear in the devices System Tray.
Sending a message direct from the firebase console to the app results in the message arriving in to the System tray.
Has anyone managed to get this working?
Here's an example of the code I'm using in Salesforce
Messaging.PushNotification msg = new Messaging.PushNotification(); Map<String, Object> notificationPayload = new Map<String, Object>(); notificationPayload.put('title','Title'); notificationPayload.put('body','Message Body'); notificationPayload.put('icon','ic_notification'); notificationPayload.put('click_action','OPEN_ACTIVITY_1'); Map<String, Object> androidPayload = new Map<String, Object>(); androidPayload.put('notification', notificationPayload); msg.setPayload(androidPayload); Set<String> users = new Set<String>(); users.add('userId'); msg.send('Android_Test', users);