Can';t使用Android的谷歌云消息(不是帮助程序库)接收消息

Can';t使用Android的谷歌云消息(不是帮助程序库)接收消息,android,push-notification,client-side,google-cloud-messaging,Android,Push Notification,Client Side,Google Cloud Messaging,有没有人可以帮我举一个使用Android的谷歌云消息从gcm接收消息的工作示例。我尝试了两种方法(helper库和GoogleCloudMessaging类),但似乎都没有效果。我使用的PHP脚本显示以下内容: 多播ID:5.2108110103215E+18 成功处理的邮件数:1 处理错误的邮件数:0 规范ID:0 所以很明显一切都没问题。我可以通过两种方式注册设备,使用helper库(gcm.jar)和GoogleCloudMessaging类。问题是我通过PHP发送的消息无法到达,或者至少

有没有人可以帮我举一个使用Android的谷歌云消息从gcm接收消息的工作示例。我尝试了两种方法(helper库和GoogleCloudMessaging类),但似乎都没有效果。我使用的PHP脚本显示以下内容:

多播ID:5.2108110103215E+18 成功处理的邮件数:1 处理错误的邮件数:0 规范ID:0

所以很明显一切都没问题。我可以通过两种方式注册设备,使用helper库(gcm.jar)和GoogleCloudMessaging类。问题是我通过PHP发送的消息无法到达,或者至少我不知道如何正确处理它。以下是我的清单中的权限和接收者:

<permission android:name="com.example.gcm.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />    
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />

<receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.example.gcm" />
        </intent-filter>
    </receiver>
<service android:name=".GCMIntentService" />
以下是使用GoogleCloudMessaging类时的代码(我将清单更改为使用自定义接收器):

}

问题是,一切似乎都很好,但信息从未到达。有什么想法吗??
提前感谢。

您的清单缺少一些权限:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.gcm.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

编辑:

在清单中,您使用的是
com.google.android.gcm.GCMBroadcastReceiver
。这是来自旧帮助程序库(
gcm.jar
)的一个类,它启动了一个intent服务。如果要使用帮助程序库,应在清单中定义意图服务


如果不想使用帮助程序库,则应将清单中的
GCMBroadcastReceiver
包更改为问题中包含的
GCMBroadcastReceiver
类的包。否则,将不使用该类。

在您的应用程序中添加以下内容:

 <permission
    android:name="PACKAGE_NAME.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />

<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />


别忘了将“com.example.gcm”更改为您的软件包名称,例如“com.yourdomain.yourapp”

您使用的是谷歌不推荐使用的GCMBaseIntentService。(但它应该仍然有效。)我遵循了最新的教程并收到了消息。你也可以试试

另一个可能的原因是您可能已收到一条消息,但该消息未成功显示在通知中。在方法中添加此行:sendNotification(String msg)


纠正上述问题后,仍然没有推送消息。问题是403错误。看起来古巴没有这项服务,所以解决办法是使用“你的自由”或“托尔”等工具。

对不起,你是对的,但将清单复制到帖子时出现了问题。我的清单实际上拥有权限,我更新了帖子。还有别的想法吗?谢谢。@AlejandroCasanova如果您正在使用问题中包含的
GCMBroadcastReceiver
类,您不需要
GCMinentService
。但是,您的清单引用了
com.google.android.gcm.GCMBroadcastReceiver
。您在问题中包含的
GCMBroadcastReceiver
的包是什么?它可能不是
com.google.android.gcm
(如果是,就不应该是)。我猜你的清单引用了谷歌默认的
GCMBroadcastReceiver
,这就是你的代码不起作用的原因。我用丢失的gcminentservice更新了清单。事实上,我有两个例子,但都不起作用。第一个将当前清单与gcminentservice和助手库一起使用。我想这次什么都不缺。第二个项目不使用helper库,清单中的接收者如下:这次没有gcminentservice。第二个例子中的接收器就是问题中的接收器。仍然卡住:(很抱歉,你是对的,但将清单复制到帖子时出现问题。我的清单实际上具有权限,我更新了帖子。还有其他想法吗?谢谢。这是我用于演示应用程序的包。这里的教程很好
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.gcm.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
 <permission
    android:name="PACKAGE_NAME.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />

<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    Log.i(TAG, msg);