Advanced Integration

This sections outlines some of the customizations that can be done in handling GCM push notifications.

Custom GCM Setup

By default, the SDK comes with a GCM receiver that handles all the notifications sent by Context360 server. If you already have a GCM receiver configured and wish to use it instead, then you need to do the following:

Initialize the SDK with GCM disabled via the initialization call as show below:

public class MainActivity extends Activity {
 
    protected static final String C360_API_KEY = <APP KEY>;
    protected static final String GCM_SENDERID = <GCM_SENDERID>;
    protected String userId = <USER IDENTIFIER>;
    ...
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ScioContext.initializeSDK(this, C360_API_KEY, GCM_SENDERID, userId, true);
        ...
    }
}

Inside the Apps' InstanceIdListenerService, call setupGCM to register the GCM token with Context360 as below:

public class MyInstanceIDListenerService extends InstanceIDListenerService {
...
   @Override
   public void onTokenRefresh() {
    ...
    // Once you get the token from instanceId.getToken()
    ScioContext.registerGCMToken(this, gcmToken);
   }
}

Finally, in the GCM Message receiver pass the incoming message bundle to Context360 message handler if it has the key context360_msg.

public class MyGcmListenerService extends GcmListenerService {
   /**
     * Called when message is received.
     */
   @Override
   public void onMessageReceived(String from, Bundle extras) {
      if (extras.containsKey("c360_message")) {
         ScioContext.handlePushMessage(this, extras);
         return;
      }
    ...
   }

Custom Push Payload

You can configure the push notifications to send in key value pairs that can accessed inside the app.
Eg: If you want to push a Promo Code notification that can be automatically applied when the user opens the App by clicking on the notification in the notification bar, you can add the code and its value to the push notification message on the dashboard under custom payload section.

Once the user clicks on the notification, the custom key value pair are loaded into the Bundle extras which can accessed as shown below:

public class MainActivity extends Activity {
...
    @Override
    protected void onNewIntent(Intent intent) {
       super.onNewIntent(intent);
       if (extras == null) {
           return;
       }
       String customPayload = extras.getString("custom_payload");
       Log.w(TAG, "Got custom payload: " + customPayload);
    }
...
}