GCM没有使用Gingerbread,但正在研究冰淇淋三明治

我正在编写一个使用GCM消息的游戏。 当一个玩家进入转向移动到服务器时,服务器将向对手发送GCM消息,让该客户知道有额外的转弯数据可用。 这应该很简单。 我尽可能地跟踪了示例GCM客户端代码。

我有两个用于测试的设备:摩托罗拉Xoom配冰淇淋三明治4.0.4版摩托罗拉X2配姜饼版2.3.5

这两个设备都有一个Goggle帐户设置(实际上是同一个帐户)。 我可以从Play商店下载应用程序。 当我收到新的Google Talk消息或Gmail消息时,我会收到有关这两者的通知消息。 他们都在我面前使用相同的Wi-Fi网络,因此我可以确认没有防火墙问题。 我在两者上安装了相同的游戏应用程序。 我已经能够在两台设备上获得GCM注册ID号。 除Android OS版本外,两款设备几乎完全相同。 但是,Xoom将接收GCM消息而X2不接收,或者至少消息未在X2上广播到我的应用程序。

这是我的清单文件:

             ... Other Activities ...           

这是我的GCMIntentService的代码:

 package myGame.app.main; import com.google.android.gcm.GCMBaseIntentService; import com.google.android.gcm.GCMRegistrar; import android.content.Context; import android.content.Intent; import android.os.PowerManager; import java.util.logging.Logger; public class GCMIntentService extends GCMBaseIntentService { private static PowerManager.WakeLock sWakeLock; private static final Object LOCK = GCMIntentService.class; private static final String GCM_SENDER_ID = "... My Sender ID..."; private static final String GCM_INTENT_FILTER = "myGame.app.main.GCM_MESSAGE"; private static final String MESSAGE_TYPE = "Type"; private static final String MESSAGE_CONTENT = "Body"; private static Logger log = Logger.getLogger(GCMIntentService.class.getName()); public GCMIntentService() { super(GCM_SENDER_ID); } static void runIntentInService(Context context,Intent intent) { synchronized(LOCK) { if (sWakeLock == null) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"sc_wakelock"); } } sWakeLock.acquire(); intent.setClassName(context,GCMIntentService.class.getName()); context.startService(intent); } @Override protected void onRegistered(Context context,String registrationId) { log.warning("From GCMIntentService: Device successfully registered as "+registrationId); ... Other Code ... } @Override protected void onUnregistered(Context context,String registrationId) { log.warning("From GCMIntentService: Device successfully unregistered"); ... Other Code ... } @Override protected void onMessage(Context context,Intent messageIntent) { log.warning("From GCMIntentService: Game update notice received"); ... Other Code ... } @Override protected void onDeletedMessages(Context context,int total) { log.warning("From GCMIntentService: Server deleted "+Integer.toString(total)+" pending messages"); } @Override public void onError(Context context,String errorId) { log.warning("From GCMIntentService: Error "+errorId); ... Other Code ... } @Override protected boolean onRecoverableError(Context context,String errorId) { log.warning("From GCMIntentService: Recoverable error "+errorId); return(super.onRecoverableError(context,errorId)); } } 

我甚至使用我自己的getGCMIntentServiceClassName()函数创建了我自己的GCMBroadcastReceiver类,并在那里放了一条日志消息。 在我尝试过的每个变体中,当应用程序在Xoom上运行时,我看到了正确的LogCat消息,但我在X2上看不到任何GCM消息的证据。 就好像GCMBroadcastReceiver和/或GCMIntentService根本不起作用,但我看不到任何类型的错误消息。

谁能帮我这个?

我编译了GCM消息的示例代码。 我所做的唯一更改是使用我在游戏应用程序中使用的相同API密钥和发件人ID。 此应用程序适用于两个设备,因此我可以再次确认没有网络问题,我可以确认X2实际上可以接收GCM消息。

坏消息是X2仍然没有收到我游戏的GCM消息。 经过更多研究后,我发现当服务器尝试向X2发送GCM消息时(仅适用于我的游戏应用程序),服务器会收到ERROR_NOT_REGISTERED结果。 发送到Xoom没有这样的错误。 我已确认服务器已成功接收注册ID号。 我知道这很难说,但注册ID在传输过程中不会受到损害。

我尝试了一些关于如何从GCM服务器取消注册设备的不同发布的建议,但似乎都没有。 我总是再次收到相同的注册ID。 所以我完全卸载了我的游戏,然后在X2上重新安装它。 这迫使它获得一个新的注册ID号,解决了这个问题。 我的游戏现在可以在两个设备上正常运行 我必须假设在我调试时,游戏和GCM服务器之间的某种方式注册ID混淆了。

我只能希望这不会成为常规问题,因为除了卸载应用程序之外似乎没有成功的修复。