Getting Gcm Error: Invalid_sender Occasionally In An App That Has Two Gcm Broadcastreceivers
Solution 1:
The Broadcasts sent by GCM seem to be ordered. This means they are delivered one at a time. It's possible that the receiver of the library sometimes gets called before your receiver, and it might prevent your receiver from being called (if it cancels the broadcast).
There are several ways to handle it. One way is to give your receiver a higher priority than the library's receiver. Just add the android:priority
attribute to the intent-filter
of both receiver, and give your receiver a higher priority.
Ordered broadcasts (sent with Context.sendOrderedBroadcast) are delivered to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers. The order receivers run in can be controlled with the android:priority attribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order.
When your broadcast receiver gets called, you should check that intent.getExtras ().get("from")
contains the sender ID you are using. Only in this case you should handle the broadcast. If it's a different sender ID, it's probably the sender ID used by the library, and you should let the library handle it.
If that doesn't solve the problem, you can consider declaring only your receiver in the manifest, and forwarding the GCM broadcast to the other receiver when necessary.
Post a Comment for "Getting Gcm Error: Invalid_sender Occasionally In An App That Has Two Gcm Broadcastreceivers"