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('body','Message Body');

Map<String, Object> androidPayload = new Map<String, Object>();
androidPayload.put('notification', notificationPayload);
Set<String> users = new Set<String>();
msg.send('Android_Test', users);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.