Android C2DM sender id

2019-09-13 18:42发布

问题:

I've been working with de C2DM for sometime and its has been working perfect. Recently I've bumped into a problem that I can't seem to fix and couldn't anything on this forum that might help. The problem is that I have several apps that use C2DM, I've let all apps register with the same sender id which then registers the users token in my database. The problem if a user has two of my apps A & B (same sender id) and launches app A and I send a push notification to users with app B, user who launched app A the last will receive a message which was actually intended for app B.

My question is there a way to use the same sender id for all apps installed on 1 device?

回答1:

No. A C2DM Registration ID is scoped to one app on one device. If a C2DM message is sent to a Registration ID, it will only ever be delivered to one app. you should have used different C2DM accounts from the start, so each app has its own registration ID. Registration IDs are not per device, they are Per App Per Device.

If you cannot reconfigure the registration IDs then you could use a receiver that then sends a broadcast intent, and both your apps could pick it up by responding to that broadcast. I expect you'd need both apps to listen-and-rebroadcast, but it should work. I'd advise you reconfigure your C2DM usage tho, as your current setup is not ideal and I expect the problem will only get worse.

I assume when you say "sender id" you mean registration id.