我即将为我的应用程序实现 C2DM,但我发现文档 http://code.google.com/android/c2dm/#writing_apps关于如何编写清单有点令人困惑。
清单代码示例包含以下内容:
<!-- 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
and com.google.android.c2dm.intent.REGISTRATION
意图。但在代码示例中,接收器的过滤器仅包含.intent.RECEIVE
and .intent.REGISTRATION
意图。哪里C2D_MESSAGE
去吧,这和我上面的问题有关系吗?
我希望这不是显而易见的事情,但我只是不明白......请帮助。