android - 在 Android 中注册 C2DM 时出现问题

标签 android android-manifest android-c2dm

我正在尝试测试 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/

相关文章:

android - 在 Android 8 Oreo 的 WifiManager 的 startscan 方法中没有收到响应

android - 尝试在从头开始训练的模型上使用 tensorflow classify android 示例时出现异常

java - Android 应用程序因 Google map 对象而崩溃

android - 我的应用程序显示 "This item is not compatible with your device"

java - 模拟器上的 Android c2dm 服务器模拟器

php - C2DM应用服务器解决方案

java - Android 在注册推送通知期间崩溃

android - 上传到bintray.com的文件有什么区别?

java - 如何在Android中使用CheckBox设置字符串

java - 需要有关应用程序类的解释