本文介绍了GCM不工作的姜饼,但正在冰淇淋三明治的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个游戏,使用GCM消息。当一个玩家进入转移动到服务器时,服务器会发送一个GCM消息,他们的对手让该客户知道更多的转数据可用。这应该是简单的。我按照样品GCM客户端code尽可能接近。

I am writing a game that uses GCM messages. When one player enters turn moves to the server, the server will send a GCM message to their opponent letting that client know that additional turn data is available. This should be simple. I have followed the sample GCM client code as closely as possible.

我有两个设备进行测试:一个摩托罗拉Xoom与冰淇淋三明治版本4.0.4摩托罗拉公司X2采用姜饼版本2.3.5

I have two devices for testing:A Motorola Xoom with Ice Cream Sandwich version 4.0.4A Motorola X2 with Gingerbread version 2.3.5

两种设备都拥有护目镜帐户设置(其实是同一帐户)。我可以下载无论是从Play商店的应用程序。我得到通知消息上都当我收到一个新的谷歌Talk消息或Gmail邮件。他们都在使用同一个Wi-Fi网络我的面前,让我可以确认没有防火墙问题。我安装了两个相同的游戏应用程序。我已经能够让两台设备上GCM注册ID号。除了Android操作系统的版本,这两个设备都几乎相同。然而,Xoom的将接收GCM消息和所述X2不,或至少所述消息不被广播到我在所述X2应用

Both devices have a Goggle account setup (in fact, the same account). I can download applications from the Play Store on both. I get notification messages on both when I receive a new Google Talk message or Gmail message. They are both in front of me using the same Wi-Fi network, so I can confirm there are no firewall issues. I have the same game application installed on both. I have been able to get a GCM registration ID number on both devices. Aside from the Android OS version, both devices are virtually identical. However, the Xoom will receive GCM messages and the X2 does not, or at least the messages are not being broadcast to my application on the X2.

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="myGame.app.main" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="myGame.app.main.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="myGame.app.main.permission.C2D_MESSAGE" />

<application android:icon="@drawable/icon" android:name="myGameApp" android:label="@string/app_name" android:description="@string/description" android:theme="@style/GlobalTheme" android:killAfterRestore="false" android:allowTaskReparenting="false" android:persistent="false">

    ... Other Activities ...

    <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="myGame.app.main" />
        </intent-filter>
    </receiver>
    <service android:name=".GCMIntentService" android:enabled="true" />
    </application>
</manifest>

这是code我GCMIntentService:

This is code for my 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中的消息,但我没有看到任何证据GCM的消息在所有的X2。这是因为如果在GCMBroadcastReceiver和/或GCMIntentService都没有任何反应,但我看到任何形式的错误消息。

I have even gone as far as creating my own GCMBroadcastReceiver class with my own getGCMIntentServiceClassName() function, and put a log message there. In every variation I have tried, I see the proper LogCat messages when the application is running on the Xoom, but I see no evidence of any GCM messages at all on the X2. It is as if the GCMBroadcastReceiver and/or GCMIntentService are not functioning at all, but I see no error messages of any kind.

谁能帮助我?

推荐答案

我整理样品$ C $下GCM的消息。我所做的唯一改变是用,我使用我的游戏应用程序相同的API密钥和发件人ID。该应用程序的工作原理两台设备上,这样我就可以再次确认不存在网络问题,我可以证实,X2实际上可以接收GCM消息。

I compiled the sample code for GCM messages. The only changes I made were to use the same API key and Sender ID that I'm using in my game application. This application works on both devices, so I can reconfirm there are no network issues and I can confirm that the X2 actually can receive GCM messages.

但坏消息是,X2仍然没有收到GCM消息我的比赛。经过研究,我发现,当服务器试图发送一个GCM消息X2(对于我的游戏应用程序只)服务器接收到一个ERROR_NOT_REGISTERED结果。不存在这样的错误发送到Xoom的。我已经证实,服务器成功接收到登记的ID号码。我知道这很难说,但注册的ID没有得到错位的传输过程。

The bad news was that the X2 still did not receive GCM messages for my game. After more research I discovered that when the server tries to send a GCM message to the X2 (for my game application only) the server receives an ERROR_NOT_REGISTERED result. There is no such error sending to the Xoom. I have confirmed that the server is successfully receiving the registration ID numbers. I know it's hard to tell, but the registration IDs do not get mangled in the transmission process.

我尝试了如何从GCM服务器注销设备几个不同的出版建议,但似乎没有工作。我总是收到相同的注册ID再回来。所以,我完全卸载我的游戏然后重新安装它的X2。这迫使它要获取的解决了这个问题一个新注册的ID号。我的游戏正常运行在两台设备上了。我必须假设,不知怎的,注册ID搞混了不知何故,游戏和GCM服务器之间,当我调试。

I tried a few different published recommendations on how to unregister the device from the GCM server but none seemed to work. I always received the same registration ID back again. So I completely uninstalled my game then reinstalled it on the X2. That forced it to get a new registration ID number which solved the problem. My game works properly on both devices now. I must assume that somehow the registration ID got mixed up somehow, between the game and GCM server, while I was debugging.

我只能希望这不会成为一项经常性的问题,因为似乎没有成为一个成功的修复比卸载应用程序等。

I can only hope that this doesn't become a regular problem, as there doesn't seem to be a successful fix other than uninstalling the application.

这篇关于GCM不工作的姜饼,但正在冰淇淋三明治的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:26