我正在尝试测试 C2DM 框架。几天前我收到了确认电子邮件,然后尝试创建一个可以注册的客户端。为此,我按照本教程中描述的步骤创建了一个简单的客户端:http ://code.google.com/intl/es-419/android/c2dm/index.html 。
Android 清单文件包含以下代码:
<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>
然后,程序启动时启动的主要活动有以下代码:
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 上注册了一个谷歌帐户,因为他们说这是必需的。但问题是我无法让广播接收器“唤醒”。我不知道有什么问题。通过分析日志,我可以看到注册意图已创建并且显然使用正确,但接收器代码从未执行过,可能有什么问题?
提前感谢尼尔森