我即将为我的应用程序实现C2DM,但是我发现文档在如何编写清单方面有点令人困惑。
清单的示例代码包含以下内容:
<!-- 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);
Service接收到registrationIntent后,如何知道要检查哪个权限?据我所知(如果我理解错误,请纠正),在声明权限时,我可以在我的命名空间中选择任何权限名称,例如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 Intents。C2D_MESSAGE去了哪里,并且它是否与我上面提出的问题有关?
希望这不是一些显而易见的东西,但我就是不懂...请帮忙。