C2DM: How to use C2D_MESSAGE permission?

不打扰是莪最后的温柔 提交于 2019-11-27 22:40:29

The receivers they claim you need at the top in the summary appears to be a mistake in the documentation, as it does not match the manifest example.

"Receivers for com.google.android.c2dm.intent.C2D_MESSAGE and com.google.android.c2dm.intent.REGISTRATION.")

I got the examples they give to work using simply the example manifest entries tweaked to match my particular application's package name.

When the C2DM code in Android sends the broadcast out (or, rather, when it looks for potential receivers to send the broadcast to), it looks for:

Find broadcast receivers for Intent: com.google.android.c2dm.intent.REGISTRATION That have the permission: .permission.C2D_MESSAGE

All C2DM messages sent to your application by the Android C2DM code will be looking for that particular permission. It's specific to your application, and simply needs to be in that structure (your application's package + ".permission.C2D_MESSAGE").

Regarding how the registration request gets the package name to use for the permissions, that is handled when you first register with the "app" extra - from the documentation:

"app is the application's ID, set with a PendingIntent to allow the registration service to extract application information."

the line in question:

registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!