Designer 10.7 | webMethods Mobile Development | Code Snippets | Configuring Your Application to Receive Push Notifications
 
Configuring Your Application to Receive Push Notifications
 
Configuring Mobile Projects to Work With Firebase Cloud Messaging on Android
Mobile Suite enables customers to set up the application to receive push notifications.
Note:
On Android, Firebase Cloud Messaging is supported for push notifications. To configure your mobile project for this, follow the procedure as described in Configuring Mobile Projects to Work With Firebase Cloud Messaging on Android.
*To prepare your mobile project to receive push notifications
1. Open your application model and locate the Application node.
2. In the Properties section, configure the Use Push Notifications property. For more information, see Application Node Properties.
3. Regenerate the Java sources. For more information, see Generating Sources for a Mobile Project.
4. Open the application_name AppControllerImpl.java class of your mobile project and override the onDeviceRegistered(String), onMessage(PushNotification), and onStartAppFromPushNotification(PushNotification) methods as follows:
public void onDeviceRegistered(final String newPushUID) {
String pushtoken = deviceRegistrationId;
if (runningOnIOS()) {
// converting the ios push token as it might come formatted
// <.... .... .... ....>
final StringTokenizer tokenizer = new StringTokenizer(
deviceRegistrationId, "/<> ");
final StringBuffer iosToken = new StringBuffer();
while (tokenizer.hasMoreElements()) {
iosToken.append((String) tokenizer.nextElement());
}
pushtoken = iosToken.toString();
}

// register the device pushtoken within the backend system the
// app will receive push notifications from. You need to call a service
// provided by the backend system.

// this.registerForPushNotification(pushtoken, this.username)
}

public void onMessage(final PushNotification notification) {
final String message = notification.getMessage();
if (message != null) {
// present message to the user
}
super.onMessage(notification);
}

public void onStartAppFromPushNotification(
final PushNotification notification) {
// process push notification
final String taskId = (String) notification.getParams().get("taskID");
if (taskId != null) {
// present task with taskId to the user
}
}
For more information, see Common Methods to Override in the Generated Code for the Application.
5. Configure your iOS and/or Android multibuilds to build your application with the correct signing required for push notifications. For more information, see Using webMethods Mobile Designer.
Related Topics