Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Enable Push Notifications in a Salesforce Mobile SDK Android App
-
Add an entry for androidPushNotificationClientId.
-
In res/values/bootconfig.xml (for
native apps):
1<string name="androidPushNotificationClientId">1234567890</string> - In assets/www/bootconfig.json (for hybrid apps):
This example value represents the project number of the Google project that is authorized to send push notifications to Android devices.
-
In res/values/bootconfig.xml (for
native apps):
-
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).
1public interface PushNotificationInterface { 2 public void onPushMessageReceived(Bundle message); 3}In this method you implement your custom functionality for displaying, or otherwise disposing of, push notifications.
-
In the onCreate() method
of your Application subclass,
call the SalesforceSDKManager.setPushNotificationReceiver() method, passing in your implementation of PushNotificationInterface. Call this method immediately
after the SalesforceSDKManager.initNative() call.
1@Override 2public void onCreate() { 3 super.onCreate(); 4 SalesforceSDKManager.initNative(getApplicationContext(), 5 new KeyImpl(), MainActivity.class); 6 SalesforceSDKManager.getInstance(). 7 setPushNotificationReceiver(myPushNotificationInterface); 8 }