我希望我不会这样做,但我一直在头脑中过去两天看起来很简单。根据google和vogella的教程,我已经实现了我的C2DM应用程序客户端+服务器。C2DM - 消息发送成功从服务器,但没有出现在设备上
我会尽量简要说明我的问题:
- 我的客户端应用程序成功接收其registrationId。
- 我的服务器成功收到其认证令牌。
- 服务器使用其认证令牌和设备的registrationId发送消息。
- 当从服务器发送消息给客户端时,我得到一个成功的消息响应代码(例如id = 0:1335303367614556%fd55792500000030响应代码:200,根据Google关于C2DM的文档应该是成功的消息)。
所以我认为最有可能我的问题是与我的接收器的消息,因为他们从我的第三方服务器发送到C2DM服务器,但不能从那里到我的应用程序。
我在StackOverflow上阅读了有关设备端口的问题,但我目前使用相同的接收器来注册应用程序和接收消息,并且注册部分每次都工作。
这里是我的接收器:
public class C2DRegistrationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null){
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")){
// do something
}
else if (action.equals("com.google.android.c2dm.intent.RECEIVE")){
// do something else
}
}
}
}
我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ro.raullepsa.coder"
android:versionCode="1"
android:versionName="1.0" >
<!-- SDK min version -->
<uses-sdk android:minSdkVersion="8" />
<!-- Only this application can receive the messages and registration result -->
<permission android:name="ro.raullepsa.coder.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="ro.raullepsa.coder.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive messages from Google's c2dm -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Permission to use internet -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- Activities -->
<activity
android:name="ro.raullepsa.coder.activity.MainActivity"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ro.raullepsa.coder.activity.RegistrationResultActivity" />
<activity android:name="ro.raullepsa.coder.activity.MessageReceivedActivity" />
<receiver
android:name="ro.raullepsa.coder.util.c2d.C2DRegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive messages -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="ro.raullepsa.coder" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="ro.raullepsa.coder" />
</intent-filter>
</receiver>
</application>
</manifest>
我没有错误,我已经尝试了一遍又一遍,以重新安装应用程序,重新注册,我已经尝试了2个独立的接收器,我已经手动强制停止了从C2DM运行并重新安装的所有服务,但仍然没有任何结果。
我试着在调试模式下等待接收器的第一行,它在注册时会到达那里,但从未从服务器发送消息之后。
我有点卡住,并会感谢任何帮助。如果需要,我可以提供更多的代码,尽管我的应用程序基本上是Lars Vogel's tutorial。我错过了什么?
您是否尝试过另一台设备上同步>后台数据? – 2012-04-24 22:02:09
实际上这是我的计划,但我还没有其他的Android设备支持这一点。如果我不能管理,我会借用朋友的设备并尝试使用他的设备。 – 2012-04-24 22:03:58
我认为这是重要的一步,因为它有助于缩小问题范围并排除单个设备的问题。也尝试在不同的网络(3G,而不是无线) - 我看到C2DM消息无法到达某些网络(虽然你可以注册好,这可能不是问题)。 – 2012-04-24 22:24:27