【发布时间】:2011-02-25 18:22:40
【问题描述】:
我即将为我的应用程序实现 C2DM,但我发现 documentation 对于如何编写清单有点混乱。
清单代码示例包含以下内容:
<!-- Only this application can receive the messages and registration result -->
<permission android:name="com.example.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" />
解释如下:
applicationPackage + ".permission.C2D_MESSAGE 防止其他应用程序注册和接收应用程序的消息。
但这究竟是如何工作的呢?据我了解,这声明了一个权限,然后为我的应用程序获取该权限。但该权限究竟是在哪里执行的呢?
注册码是:
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender", emailOfSender);
startService(registrationIntent);
接收到registrationIntent的Service如何知道要检查什么权限?据我了解(如果我在这里错了,请纠正我),在声明权限时,我可以在我的命名空间中选择任何权限名称,例如com.example.myapp.permission.WHATEVER.
还是 C2D_MESSAGE 是我必须使用的一些魔法常数?
此外,文档说我必须为com.google.android.c2dm.intent.C2D_MESSAGE 和com.google.android.c2dm.intent.REGISTRATION Intents 实现接收器。但在代码示例中,接收者的过滤器只包含.intent.RECEIVE 和.intent.REGISTRATION Intent。 C2D_MESSAGE去哪儿了,和我上面的问题有关系吗?
我希望这不是很明显,但我就是不明白...请帮忙。
【问题讨论】:
标签: android android-c2dm