Reputation: 169
I'm implementing push notifications for Android. My client wants the app to support Urban Airship in addition to normal GCM service. Here I'm having a problem.
To enable GCM, I used Google's gcm.jar and have done all other setup and confirmed that I can send push notifications from my server without problem. This is a part of AndroidManifest.
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package.name"/>
</intent-filter>
</receiver>
<service android:name="my.package.name.GCMIntentService" />
And to implement Urban Airship, I used urbanairship-lib-3.1.0.jar and have done all setup. Works fine.
<receiver android:name="com.urbanairship.CoreReceiver" />
<receiver android:name="com.urbanairship.push.GCMPushReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package.name"/>
</intent-filter>
</receiver>
Problem: When I send a push from Urban Airship, the app gets 2 notifications.
When it happens, I can suppress one unnecessary alert window by writing a code to do so, but I can't figure out how to eliminate the one in top notification bar.
I'm not sure if this is a correct way to use both GCM and Urban Airship in the same app. Has anyone ever succeeded that, or any other idea? Can I do something with intent-filter, maybe?
Upvotes: 1
Views: 2690
Reputation: 393821
As far as I know, urban airship use GCM to send notifications to Android. That means that regardless of who is sending the notification at the server side, a single receiver can receive all the messages. That's why you get two notifications, since both receivers get the same message and display the notification. Your own receiver can handle both the messages sent by you and by Urban Airship.
The only reason to have two different receivers is if you want your app to handle messages from one source differently than messages from the other source. In this case you should use a different sender, and each receiver would have to check the sender of the message to decide whether it should handle it.
Beside that, I don't see how sending messages via Urban Airship would make them arrive faster, since they are also sending the message to GCM servers, which do the actual delivery. The only way Urban Airship can be faster, is if they are using the Cloud Connection Server API while you are using the simpler HTTP API for direct calls to GCM.
Upvotes: 1