(Optional) The application should register and implement a listener interface to receive native or payload push notifications.
To enable push notifications, include the gcm.jar available at SUP_HOME\MobileSDK<Version>\OData\Android\libraries\ in your application project. For more information, refer to the information available in http://developer.android.com/guide/google/gcm/gs.html .
The IODPPushNotificationListener interface should be implemented by the application to receive the GCM native push notifications on Android devices. The registerForNativePush method in the ODPClientConnection class is used to register native push notifications. The onGCMNotification method is called when a new GCM push notification is received. For more information on configuring GCM native notifications on SCC, see GCM Native Notification Properties in Sybase Control Center for Sybase Unwired Platform.
The following code illustrates how to register listeners for native push notifications.
public class MyPushListener implements IODPPushNotificationListener { public int onGCMNotification(Hashtable hashValues) { // Utilize notification log.i(“GCM Notification received”); Return 0; } MyPushListener myPushListener = new MyPushListener(); ODPClientConnection.getInstance().registerForNativePush (myPushListener); }
To consume push messages, the application registers a listener object.The client SDK notifies this listener object whenever there is a push message from the server. The listener object should implement the ISDMNetListener interface.
public class MyPushListener implements ISDMNetListener{ @Override public void onError(ISDMRequest arg0, ISDMResponse arg1, ISDMRequestStateElement arg2) { Log.i("Error receiving push notification"); } @Override public void onSuccess(ISDMRequest arg0, ISDMResponse arg1) { // TODO Auto-generated method stub Log.i("Push notification received successfully"); } } MyPushListener myPushListener = new MyPushListener(); ODPClientConnection.getInstance().registerForPayloadPush(myPushListener); }