我正在尝试测试 C2DM 框架。几天前我收到了确认电子邮件,然后尝试创建一个可以注册的客户端。为此,我按照本教程中描述的步骤创建了一个简单的客户端:http://code.google.com/intl/es-419/android/c2dm/index.html .
Android list 文件包含以下代码:
<permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.bilthon.ufrj" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.bilthon.ufrj" />
</intent-filter>
</receiver>
然后,程序启动时启动的主要 Activity 有以下代码:
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender","mytestemail@gmail.com");
Log.d("WelcomeScreen","mytestemail@gmail.com");
startService(registrationIntent);
我还在运行我的客户端的 AVD 上注册了一个谷歌帐户,因为他们说这是必需的。但问题是我无法让广播接收器“醒来”。我不知道出了什么问题。通过分析日志,我可以看到注册 Intent 已创建并且显然已正确使用,但接收器代码从未执行过,这可能是哪里出了问题?
提前致谢 尼尔森
最佳答案
嗯.. 刚刚解决了,问题出在接收者的声明上。接收器的标签应该放在应用程序标签内,就像这里演示的那样:http://developer.android.com/guide/topics/manifest/manifest-intro.html
以下是 C2DM 应用程序的格式良好的 list 示例。感谢 Mark Murphy 在 android-c2dm 组发布链接。
很抱歉犯了这个愚蠢的错误。
尼尔森
关于android - 在 Android 中注册 C2DM 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3645247/