How to determine the source of GCM broadcast notification?

140 Views Asked by At

I have an existing handling for push notification directly sent from our backend server. But now, I want to support urban-airship for push delivery without breaking existing flow. So I have defined an IntentReceiver for UA notification (besides existing GcmIntentReceiver). But the problem is, now both the receivers are getting invoked. How can I determine and skip any particular callback depending upon which delivery method is used?

1

There are 1 best solutions below

0
ralepinski On

The easiest way would be to use 2 different senders. Create a new sender for Urban Airship and set as the 'gcmSender', then add your existing sender as an 'additionalGCMSenderIds' in the Urban Airship config. This will allow Urban Airship to register both senders for the application, and UA will only handle intents form the 'gcmSender'. Then in your existing GCM intent receiver you need to filter out intents from the Urban Airship sender ID by checking the "from" extra on the intent.

String sender = intent.getStringExtra("from");
if (APP_SENDER.equals(sender)) {
  // GCM Intent from your existing sender
}