Code Modifications (Android)
To configure your Mobile SDK app to support push notifications:
- Identify which version of Mobile SDK you're using.
-
For Mobile SDK 12.0 and later, Add a Firebase Configuration File as described in the Google Firebase docs.
-
For Mobile SDK 11.1 and prior, add an entry for
androidPushNotificationClientId
.-
In
res/values/bootconfig.xml
(for native apps): -
In
assets/www/bootconfig.json
(for hybrid apps):
This value is the project number of the Google project that is authorized to send push notifications to an Android device.
Behind the scenes, Mobile SDK automatically reads this value and uses it to register the device against the Salesforce connected app. This validation allows Salesforce to send notifications to the connected app. At logout, Mobile SDK also automatically unregisters the device for push notifications.
-
-
Create a class in your app that implements
PushNotificationInterface
.PushNotificationInterface
is a Mobile SDK Android interface for handling push notifications.PushNotificationInterface
has a single method,onPushMessageReceived(Bundle message)
:In this method, you implement your custom functionality for displaying, or otherwise disposing of, push notifications.
-
In the
onCreate()
method of yourApplication
subclass, call theSalesforceSDKManager.setPushNotificationReceiver()
method, passing in your implementation ofPushNotificationInterface
. Call this method immediately after theSalesforceSDKManager.initNative()
call. For example:
In Android apps, decryption of Notification Builder push notifications occurs automatically. Apex push notifications are not encrypted.